Question

I'm using VS 2008 with Intel(R) Fortran Compiler version 10.1.025.

To build my solution I'm using a batch file with the following syntax:

devenv /rebuild "Release|Win32" "c:...\solution.sln" /Project "ProjectName_InTheSolution"

Using the configuration "Release|Win32" I specify, in VS ProjectProperties->Fortran->Proprocessor->Preprocessor Definitions the value "test".

Inside my code I'm testing if the "test" variable is define which is working everything correctly.

Any one know any way to change the "Preprocessor Definitions" of the fortran compiler using the command line ? I want to add also the value "commandLine" so would be "test;commandline" in the "Preprocessor Definitions".

Some notes:

1) I have to use the devenv.exe
2) I don't want to change neither the source code or the project file prior the compilation
3) I can use environment variable to pass option (if there is any way, I try the CL but didn't work)

Thanks in advance


Thanks for your answer but maybe I didn't understand completely your solution, but this is what I tried:

1)I change the "Additional Options" (AO) to /Dtest and: 1.1) If I compile from the Visual Studio or Command Line the check "!DEC$ IF DEFINED (test)" is true

2)I changed the AO to "$(DEFINE)" and: 2.1) From Visual Studio I see warnings: "command line warning #10161: unrecognized source type '$(DEFINE)'; object file assumed ifort " and the check "!DEC$ IF DEFINED (test)" is false 2.2) I add the Define variable to "User environment variables", same error from 2.1

3) I change the AO to "/D$(DEFINE)" I got an error "Bad syntax, '=' expected while processing '@$(define)' fortcom "

4) I change the AO to "$(DEFINE)" and SET DEFINE=/test, and didn't work either, the "!DEC$ IF DEFINED (test)" is false

@cup I think I need to understand a little better your solution, if you please could give me an additional information about your solution would be very appreciated.

What I'm trying to do is this:

program main
integer:: ii
!DEC$ IF DEFINED (test) 
ii = 72
!DEC$ ENDIF
!DEC$ IF DEFINED (test2) 
ii = 80
!DEC$ ENDIF
print *, "this is up to column ", ii
end

Now I want to control from the command line which part of code will be compiled, doing something like this:

1) from the command line:  set define=test
2) devenv elephant.sln /build
3) run debug/elephant.exe  -> get "72"

4) from the command line:  set define=test2
5) devenv elephant.sln /build
6) run debug/elephant.exe  -> get "80"

This is possible ? Thanks in advance, rui

Was it helpful?

Solution

Try this

1) Create the following F77 program

      program main
      integer:: ii
!                                                                       ,-- column 73
      ii = 72                                                           +8
      print *, "this is up to column ", ii
      end

2) Create a solution for the above program, say elephant.sln

If you just build and run, it should display "this is up to column 72"

3) Pop up project properties, under Fortran/Command Line, add $(DEFINES) in the Additional Options Box.

4) Save and exit

5) set DEFINES=/extend_source:72

6) devenv elephant.sln /build

7) run debug/elephant.exe - you should get 72

8) set DEFINES=/extend_source:80

9) devenv elephant.sln /build

10) run debug/elephant.exe - you should get 80.

11) If you wish to add more /D options, stick it in the DEFINES environment variable.

Basically don't use preprocessor defines - just dump your settings into the DEFINES environment variable and it will be picked up by the Additional Options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top