- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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 kopiert
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Add the -fpp switch.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Your program contains the directive #ELIF instead of #ELSE.
#IFDEF <symbol>
..
#ELIF <condition>
..
#ENDIF
versus
#IFDEF <symbol>
..
#ELSE
..
#ENDIF
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
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.
- Als neu kennzeichnen
- Lesezeichen
- Abonnieren
- Stummschalten
- RSS-Feed abonnieren
- Kennzeichnen
- Anstößigen Inhalt melden
Thanks a lot. After fixing a few typos, now it works.

- RSS-Feed abonnieren
- Thema als neu kennzeichnen
- Thema als gelesen kennzeichnen
- Diesen Thema für aktuellen Benutzer floaten
- Lesezeichen
- Abonnieren
- Drucker-Anzeigeseite