fpm currently has limited support for source file includes which I notice are used a lot in existing packages and are fundamental to c libraries. Specifically:
.f90 suffixI am currently working on an update to fpm to address these shortcomings.
While trying to use fpm (incredible effort by all the developers btw, thank you!) in one of my
projects, I have encountered a problem when using include statements with the nagfor compiler.
Nagfor fails to compile since it cannot locate include files (named *.inc, located along with
all other *.f90 source files in the ./src directory). The very same directory structure works
as expected when using gfortran or ifort to compile.
Searching through fpm's documentation and issues for a solution, lead me to this particular issue,
and since I could not find particular mention being made of nagfor in this context before, thought
it could be useful to share this very simple reproducer. (Assuming of course that I am using fpm as
intended, very possible that a naming/other mistake on my side is causing the trouble)
fpm new fpm_inc --app --src
Put the subroutine say_hello from src/fpm_inc.f90 into a separate file
src/say_hello.inc and modify src/fpm_inc.f90 to include this file:
! src/fpm_inc.f90
module fpm_inc
implicit none
private
public :: say_hello
contains
include 'say_hello.inc'
end module fpm_inc
! src/say_hello.inc
subroutine say_hello
print *, "Hello, fpm_inc!"
end subroutine say_hello
This project builds successfully with gfortran (default) and ifort:
fpm run
+ build/gfortran_debug/app/fpm_inc
Hello, fpm_inc!
```
fpm run --compiler ifort
However, it fails with nagfor, which complains that it cannot open the include file
fpm run --compiler nagfor
+ nagfor -c ./src/fpm_inc.f90 -g -C=all -O0 -gline -PIC -mdir build/nagfor_debug/fpm_inc -I build/nagfor_debug/fpm_inc -o build/nagfor_debug/fpm_inc/src_fpm_inc.f90.o
NAG Fortran Compiler Release 6.2(Chiyoda) Build 6207
Error: ./src/fpm_inc.f90, line 7: Cannot open INCLUDE file "say_hello.inc": No such file or directory
Error: ./src/fpm_inc.f90, line 8: Implicit type for SAY_HELLO
[NAG Fortran Compiler pass 1 error termination, 2 errors]
Command failed
ERROR STOP
In this trivial case, the include is easy to avoid. However, in my actual use case the include
file implements an algorithm using kind specifiers inherited from the module scope (so a form of
"_poor man's templates_"), with different modules defined for different kinds.
According to nagfor's documentation:
Non-intrinsic modules, INCLUDE files and #include files are expected to exist in the current working directory or in a directory named by an -I option.
Which would imply that an additional -I ./src can solve the problem in this particular case? But
this is surely not the general solution.
PS: You may notice from the code snippet, that I built fpm from source (using a binary release)
and removed -coarray=single from the compiler flags. Since this is a feature (introduced in
release 7.0) not supported by the release of nagfor that I have access to (Release 6.2).
Many thanks for the detailed report @jbdv-no, it looks like nagfor behaves slightly differently to gfortran and ifort which first search in the directory of the current source file. The solution for this issue will make the include directory explicit and so should fix your issue also.
Most helpful comment
While trying to use fpm (incredible effort by all the developers btw, thank you!) in one of my
projects, I have encountered a problem when using
includestatements with the nagfor compiler.Nagfor fails to compile since it cannot locate include files (named
*.inc, located along withall other
*.f90source files in the./srcdirectory). The very same directory structure worksas expected when using gfortran or ifort to compile.
Searching through fpm's documentation and issues for a solution, lead me to this particular issue,
and since I could not find particular mention being made of nagfor in this context before, thought
it could be useful to share this very simple reproducer. (Assuming of course that I am using fpm as
intended, very possible that a naming/other mistake on my side is causing the trouble)
Reproducing the problem
fpm new fpm_inc --app --srcPut the subroutine
say_hellofromsrc/fpm_inc.f90into a separate filesrc/say_hello.incand modifysrc/fpm_inc.f90toincludethis file:This project builds successfully with gfortran (default) and ifort:
```
fpm run --compiler ifort
Hello, fpm_inc!
```
However, it fails with nagfor, which complains that it cannot open the include file
In this trivial case, the
includeis easy to avoid. However, in my actual use case the includefile implements an algorithm using kind specifiers inherited from the module scope (so a form of
"_poor man's templates_"), with different modules defined for different kinds.
According to nagfor's documentation:
Which would imply that an additional
-I ./srccan solve the problem in this particular case? Butthis is surely not the general solution.
PS: You may notice from the code snippet, that I built fpm from source (using a binary release)
and removed
-coarray=singlefrom the compiler flags. Since this is a feature (introduced inrelease 7.0) not supported by the release of nagfor that I have access to (Release 6.2).