- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am interested in using conditional compiling using ifort. I have the following simple code with name test.f90
program ConditionalCompiling
implicit none
#IFDEF Flag
write(*,*)"Compiled with Flag defined"
#ELIF
write(*,*)"Not Compiled with Flag defined or compiled with Flag not defined"
#ENDIF
end program ConditionalCompiling
However, when I use ifort -c test.f90. It gives me the following message. Can you help me to get it compiled and behave as expected? Thanks a lot!
Intel(R) Visual Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 12.1.5.344 Build 20120612
Copyright (C) 1985-2012 Intel Corporation. All rights reserved.
test.F90(4): warning #5117: Bad # preprocessor line
#IFDEF Flag
-^
test.F90(6): warning #5117: Bad # preprocessor line
#ELIF
-^
test.F90(8): warning #5117: Bad # preprocessor line
#ENDIF
-^
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Add the -fpp switch.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve, thanks a lot for your quick response. When I use
ifort -c -fpp test.f90
I got:
test.f90(6): #error: #if: parse error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your program contains the directive #ELIF instead of #ELSE.
#IFDEF <symbol>
..
#ELIF <condition>
..
#ENDIF
versus
#IFDEF <symbol>
..
#ELSE
..
#ENDIF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, this fixes the issue. Thanks a lot! Now I have another question. If defined flag, I want to include file1.f90, if not defined include file2.f90. How can this be done? I tried the following. It does not work.
#IFDEF Flag
include 'file1.f90'
#else
include 'file2.f90'
#ENDIF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you remember to use the /fpp or -fpp option?
Simply saying "It does not work" is not helpful. You have to describe the command that you used, provide information regarding the contents of the source file, and display the error messages that you saw.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Attached are three files. When I compile using
ifort -fpp test.f90 -o test
I execute test and obtain
15.00000
Not Compiled with Flag defined or compiled with Flag not defined
When I compile using
ifort -DFlag -fpp test.f90 -o test
I execute test and obtain
15.00000
Compiled with Flag defined
I was expecting the second number to be 200.00000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Preprocessors (originating in relation to C rather than Fortran) are usually case sensitive. Make sure that your preprocessor macros such as #ifdef are lowercase, and that macro arguments such as FLAG, etc., are uppercase (or at least consistently cased). You spelled "include" as "inlcude" in one place.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot. After fixing a few typos, now it works.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page