Gfortran include path - is there an alternative to passing multiple -I options?

I have Fortran code that uses included modules, and I'm wondering which environment variables really work to set the include path.

To test this, I used one of the NAG code examples.

It works:

$ gfortran e04ucfe.f90 -lnag_nag -I/opt/NAG/fll6a23dfl/nag_interface_blocks

This does not work:

$ export CPATH=/opt/NAG/fll6a23dfl/nag_interface_blocks
$ gfortran e04ucfe.f90 -lnag_nag
e04ucfe.f90:10.37:

       USE nag_library, ONLY : nag_wp
                                     1
Fatal Error: Can't open module file 'nag_library.mod' for reading at (1): No such file or directory

However, the GCC / GFortran documentation states that:

The gfortran compiler currently does not use any environment variables to control its operation above and above those that affect the gcc operation.

(see https://gcc.gnu.org/onlinedocs/gfortran/Environment-Variables.html and https://gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html#Environment-Variables )

ltrace - gfortran , (, PATH), CPATH.

:

gfortran e04ucfe.f90 -lnag_nag `echo -I$CPATH | sed -e 's/:/ -I/'`

... ? CPATH gcc, , C/++, gfortran? -, , CPATH gcc gfortran, -I?

: LIBRARY_PATH , -L/path/to/libs gfortran.

+4
2

, gfortran , . . script gfortran $PATH, , gfortran , , $CPATH -I :

#!/bin/bash
/path/to/gfortran $(for i in ${CPATH//:/ }; do echo -I"$i"; done) "$@"

. , $PATH /home/amaurea/local/bin:/usr/local/bin:/usr/bin:/bin gfortran /usr/local/bin,

$ cd /home/amaurea/local/bin
$ cat <<HERE > gfortran
#!/bin/bash
/usr/bin/gfortran $(for i in ${CPATH//:/ }; do echo -I"$i"; done) "$@"
HERE
$ chmod a+x gfortran

, .

+2

Makefiles, subst. : -I .

usr/bin/gfortran e04ucfe.f90 -lnag_nag -I${subst :, -I,$(CPATH)}
0

Source: https://habr.com/ru/post/1542895/


All Articles