Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

preprocessor include path differences

henry_b_
Beginner
4,564 Views

I'm trying to compile code I have written, using both ifort and gfortran. The problem I am having is relating to my use of the preprocessor and directory structure.

In my fortran source I have something like:

#include "includes/myinclude1.inc"

In  "includes/myinclude1.inc" I want to include another file, say "includes/sub/myinclude2.inc".

In ifort the preprocessor uses the directory relative to the source directory, so in "includes/myinclude1.inc" I may just do:

#include "includes/sub/myinclude2.inc"

However, in gfortran it is relative to the location of the current include file, so I instead must do:

#include "sub/myinclude2.inc"

Is there a compiler option (either in ifort or gfortran) that will allow me to get the same behavior across compilers?

Thanks.

0 Kudos
21 Replies
Casey
Beginner
4,076 Views

Are you calling fpp directly or are you calling it implicitly by using input files with F suffixes (e.g. .F. F90, etc)?  

One fix is to supply a -I flag to ifort, e.g. -Iincludes , which will allow all relative include paths from that directory to be found.  The man page for fpp does say that the current directory of the include file is in the search path for "" includes, but in a quick test I did, and in your case, that does not appear to be the case.  

A second alternative is to use the GNU preprocessor "cpp" to preprocess your source and then compile the resulting fortran files with ifort.  

0 Kudos
TimP
Honored Contributor III
4,076 Views

gfortran pre-processing is available separately from full compilation by

gfortran -E file.F > file.f

or

gcc -E -traditional -x c file.F > file.f

As Casey hinted, many people do this to get consistent pre-processing.

For Windows compatibility, the files need to be written in a separate directory from the original.

0 Kudos
Steven_L_Intel1
Employee
4,076 Views

The problem where the Intel Fortran preprocessor did not do source-relative #includes is fixed in the compiler version being released in early September.  For reference, the issue ID is DPD200151471.

0 Kudos
henry_b_
Beginner
4,076 Views

Steve Lionel (Intel) wrote:

The problem where the Intel Fortran preprocessor did not do source-relative #includes is fixed in the compiler version being released in early September.  For reference, the issue ID is DPD200151471.

Thanks Steve. With the update, will there be a compiler flag that allows one to use the current preprocessing mode (i.e. fortran- rather than include-source relative paths)? 

0 Kudos
Steven_L_Intel1
Employee
4,076 Views

There already is such a flag: -assume nosource_include. The compiler honors this today for Fortran INCLUDE, but the preprocessor does not. With the fix, the preprocessor will honor -assume source_include, which is the default.

I assume that by "fortran-relative" you mean "current directory-relative".

0 Kudos
henry_b_
Beginner
4,076 Views
Hello Steve, Is this issue meant to be fixed in ifort 14.0, or am I misunderstanding something? The directory structure is: [fortran] main.f90 includes |----level1.inc |----level2.inc [/fortran] file main.f90: [fortran] program main implicit none integer, parameter :: this = 42 # include "includes/level1.inc" end program main [/fortran] file includes/level1.inc [fortran] # include "level2.inc" [/fortran] file includes/level2.inc [fortran] print *, this [/fortran] This does not compile either with nosource_include or source_include assumed (it doesn't find level2.inc, unless it is included as "includes/level2.inc", which then doesn't work with other preprocessors) Thanks.
0 Kudos
Casey
Beginner
4,076 Views

Cant say if its a bug or intented, but it looks like there is a difference in how fpp and cpp treat "nested" #include directives.  It looks like the fpp search path is the cwd of the .F90 file whereas cpp uses the cwd of the included file.  I'll defer to others on if that is the intent.

For workarounds, use

[bash]ifort -Iincludes -fpp -o main main.f90[/bash]

or, rename main.f90 to main.F90 and do

[bash]cpp -P main.F90 > main.f90

ifort -o main main.f90[/bash]

You can also invoke the c pre-processor as "gcc -E -P" or "icc -E -P" with the same results. 

0 Kudos
Steven_L_Intel1
Employee
4,076 Views

The difference Casey notes is the bug that was fixed in the 14.0 compiler. Henry, are you using the 14.0 compiler and seeing unexpected results? The default for fpp should now be that #include starts relative to the file that has the #include.

0 Kudos
henry_b_
Beginner
4,076 Views

Steve,

I am using ifort 14.0 and am still experiencing the same problem

Thanks.

0 Kudos
Casey
Beginner
4,076 Views

Steve,

   I'll also add that the behavior I noted was observed in version 14.0 of ifort. (14.0.0 20130728)

Versions:

[bash]

casey@convect ~/code/iforttest/inctest $ ifort --version
ifort (IFORT) 14.0.0 20130728
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.

casey@convect ~/code/iforttest/inctest $ icc --version
icc (ICC) 14.0.0 20130728
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.

casey@convect ~/code/iforttest/inctest $ gcc --version
gcc (Gentoo 4.7.3 p1.0, pie-0.5.5) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

casey@convect ~/code/iforttest/inctest $ fpp -V
Intel(R) Fortran Preprocessor for applications running on Intel(R) 64, Version 14.0.0.080 Build 20130728
Copyright (C) 1985-2013 Intel Corporation. All rights reserved.
# 1 "stdin"
^C

[/bash]

The files:

[bash]

casey@convect ~/code/iforttest/inctest $ cat main.F90
program main
implicit none
integer, parameter :: this = 42
#include "includes/level1.inc"
end program main

casey@convect ~/code/iforttest/inctest $ cat includes/level1.inc
#include "level2.inc"


casey@convect ~/code/iforttest/inctest $ cat includes/level2.inc
print *, this

[/bash]

The tests

ifort:

[bash]:

casey@convect ~/code/iforttest/inctest $ ifort -E -P main.F90
program main
implicit none
integer, parameter :: this = 42
level1.inc(1): #error: can't find include file: level2.inc
end program main

[/bash]

ifort with -I:

[bash]

casey@convect ~/code/iforttest/inctest $ ifort -Iincludes -E -P main.F90
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main

[/bash]

fpp:
[bash]casey@convect ~/code/iforttest/inctest $ fpp -P main.F90
program main
implicit none
integer, parameter :: this = 42
level1.inc(1): #error: can't find include file: level2.inc
end program main
[/bash]

fpp with -I:
[bash]casey@convect ~/code/iforttest/inctest $ fpp -Iincludes -P main.F90
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main
[/bash]

GNU cpp:
[bash]casey@convect ~/code/iforttest/inctest $ cpp -P main.F90
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main
[/bash]

preprocessor invoked by icc:
[bash]casey@convect ~/code/iforttest/inctest $ icc -E -P main.F90
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main
[/bash]

preprocessor invoked by gcc:
[bash]casey@convect ~/code/iforttest/inctest $ gcc -E -P main.F90
program main
implicit none
integer, parameter :: this = 42
print *, this
end program main
[/bash]

0 Kudos
Steven_L_Intel1
Employee
4,076 Views

Sigh...  We fixed only part of the problem. -assume source_include is supposed to be the default. It is for the compiler but not for fpp. The part we fixed was that even if you explicitly specified -assume source_include, it wasn't being applied to fpp. We'll fix this. For now, add -assume source_include to the compile options and it should work the way you want. Issue ID is DPD200247863.

0 Kudos
henry_b_
Beginner
4,076 Views
Steve, I can not get this working even by specifying -assume source_include: My output: [fortran] henry@xc:~/iforttest$ ifort --version ifort (IFORT) 14.0.0 20130728 Copyright (C) 1985-2013 Intel Corporation. All rights reserved. henry@xc:~/iforttest$ cat main.f90 program main implicit none integer, parameter :: this = 42 # include "includes/level1.inc" end program main henry@xc:~/iforttest$ cat includes/level1.inc # include "level2.inc" henry@xc:~/iforttest$ cat includes/level2.inc print *, this henry@xc:~/iforttest$ ifort -fpp -assume source_include main.f90 level1.inc(1): #error: can't find include file: level2.inc [/fortran] Thanks
0 Kudos
Steven_L_Intel1
Employee
4,076 Views

Hmm - it works when I try it. Would you also add -watch to the ifort command and show me the output?

0 Kudos
henry_b_
Beginner
4,076 Views

[bash]
~/iforttest$ ifort -fpp -watch -assume source_include main.f90
echo main.f90
main.f90
/opt/intel/composer_xe_2013_sp1.0.080/bin/intel64/fpp \
-D__INTEL_COMPILER=1400 \
-D__INTEL_COMPILER_UPDATE=0 \
-D__unix__ \
-D__unix \
-D__linux__ \
-D__linux \
-D__gnu_linux__ \
-Dunix \
-Dlinux \
-D__ELF__ \
-D__x86_64 \
-D__x86_64__ \
-D_MT \
-D__INTEL_COMPILER_BUILD_DATE=20130728 \
-D__INTEL_OFFLOAD \
-D__i686 \
-D__i686__ \
-D__pentiumpro \
-D__pentiumpro__ \
-D__pentium4 \
-D__pentium4__ \
-D__tune_pentium4__ \
-D__SSE2__ \
-D__SSE__ \
-D__MMX__ \
-I. \
-I/opt/intel/composer_xe_2013_sp1.0.080/mkl/include \
-I/opt/intel/composer_xe_2013_sp1.0.080/compiler/include/intel64 \
-I/opt/intel/composer_xe_2013_sp1.0.080/compiler/include \
-I/usr/local/include \
-I/usr/lib/gcc/x86_64-linux-gnu/4.6/include \
-I/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed \
-I/usr/include \
-I/usr/include/x86_64-linux-gnu \
-free \
-4Ycpp \
-4Ncvf \
-f_com=yes \
main.f90 \
/tmp/ifortkNe6fW.i90

level1.inc(1): #error: can't find include file: level2.inc
rm /tmp/ifortlibgccfbGIFr
rm /tmp/ifortgnudirsmo2lj4
rm /tmp/ifort6CnOBj.o
rm /tmp/ifortkNe6fW.i90
rm /tmp/ifortdummyD5fpUy.c
rm /tmp/ifortdashvTBEJyb
rm /tmp/ifortargDm09eO
rm /tmp/ifort6CnOBj.o
[/bash]

0 Kudos
Steven_L_Intel1
Employee
4,076 Views

Are you still using a beta version? Please upgrade to the released version.

0 Kudos
henry_b_
Beginner
4,076 Views

Steve,

I have never used the beta for version 14. I only download this after it was announced and the build date above 20130728 is exactly the same as I see on the (non-commerical) download page.

Thanks.

0 Kudos
Steven_L_Intel1
Employee
4,076 Views

My mistake - you have the released version. I'm not used to the Linux and Windows build numbers being so far apart. Let me look into this further.

0 Kudos
henry_b_
Beginner
4,076 Views

Hello Steve, were you able to reproduce this issue?

Thanks,

0 Kudos
Steven_L_Intel1
Employee
4,076 Views

Yes, I can. Sorry for the delay getting back to you.  It's not quite the same scenario we were working with earlier. Let me talk to the developers about it.

0 Kudos
henry_b_
Beginner
3,797 Views

Steve Lionel (Intel) wrote:

Yes, I can. Sorry for the delay getting back to you.  It's not quite the same scenario we were working with earlier. Let me talk to the developers about it.

 

Hello Steve,

Is there any progress on this issue? What was the response of the developers?

Thanks

0 Kudos
Reply