I have a program need to link external library and module, so in fpm.toml I have:
[build]
link = “mylib”
external-modules = “mymodule”
and FPM_LDFLAGS environment variable is defined as absolute path using options “-I” and “-L”. This does work in a regular plain system using self-installed fpm package.
However, once in a conda environment using conda’s fpm package, fpm gives error mymodule can’t be found. The fpm.toml and FPM_LDFLAGS variable are still the same as before.
what version of fpm is available in conda? you can check it by running
federico@MacBookPro amr % fpm --version
Version: 0.11.0, alpha
Program: fpm(1)
Description: A Fortran package manager and build system
Home Page: https://github.com/fortran-lang/fpm
License: MIT
OS Type: macOS
what happens if you pass those flags via the fpm CLI interface instead?
I am no Conda user, but is it possible that it creates a new environment, so the FPM_LDFLAGS need be set again after the conda environment is initiated?
Another option would be to please share the output of fpm --verbose, that should give us more information.
It is the same if passing flags on fpm CLI. My fpm.toml file build section is listed below:
[build]
auto-executables = false
auto-tests = false
auto-examples = false
link = "mylib"
external-modules = "mymodule"
[dependencies]
stdlib = "*"
[[test]]
name = "test_add"
main = "test_add.f90"
The libmylib.a and mymodule.mod is in /home/jing/mylib/build directory.
I have updated my system wide installed fpm version to 0.11.0, now I have the same problem as in conda environment which has the latest version of 0.10.1
Here is the output:
(fortran) [jing@Lenovo myproject]$ fpm --verbose test --link-flag "-I$HOME/mylib/build/ -L$HOME/mylib/build/"
<INFO> BUILD_NAME: build/gfortran
<INFO> COMPILER: gfortran
<INFO> C COMPILER: gcc
<INFO> CXX COMPILER: g++
<INFO> COMPILER OPTIONS: -cpp -Wall -Wextra -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single
<INFO> C COMPILER OPTIONS:
<INFO> CXX COMPILER OPTIONS:
<INFO> LINKER OPTIONS: -I/home/jing/mylib/build/ -L/home/jing/mylib/build/
<INFO> INCLUDE DIRECTORIES: []
+ mkdir -p build/gfortran_7BA72E36968DE660
[ 0%] test_add.f90
+ gfortran -c test/test_add.f90 -cpp -Wall -Wextra -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -fimplicit-none -Werror=implicit-interface -ffree-form -J build/gfortran_6E2E351FB09955DB -Ibuild/gfortran_6E2E351FB09955DB -Ibuild/gfortran_1D6428BD3EB87848 -o build/gfortran_6E2E351FB09955DB/myproject/test_test_add.f90.o
test/test_add.f90:6:9:
6 | use mymodule
| 1
Fatal Error: Cannot open module file 'mymodule.mod' for reading at (1): No such file or directory
compilation terminated.
[ 50%] test_add.f90 done.
test/test_add.f90:6:9:
6 | use mymodule
| 1
Fatal Error: Cannot open module file 'mymodule.mod' for reading at (1): No such file or directory
compilation terminated.
<ERROR> Compilation failed for object " test_test_add.f90.o "
<ERROR> stopping due to failed compilation
STOP 1
@icpup, from what you are showing, I believe the -I/home/jing/mylib/build/ should be a build flag rather than a link flag, and it may be the reason why the compiler can’t find the module files.