I found what was the issue.
I forgot that the dependency on stdlib is no more part of the package, as each dependency is compiled separately, and therefore must be treated as an “external” dependency. The link option needs to be declared in the [build] section.
fpm.toml
name="mytest"
...
Package:
app
main.f90
src
core.f90
- Default settings in
fpm.toml
name="mytest"
...
[library]
type="monolithic"
[dependencies]
stdlib="*"
...
Everything compiles fine as usual.
- Settings for shared library in
fpm.toml
name="mytest"
...
[library]
type="shared"
[dependencies]
stdlib="*"
...
libstdlib.so is compiled fine
libmytest.so is compiled but NOT linked to libstdlib.so:
+ gfortran -shared build/gfortran_2B4944C3A077DCE8/mytest/src_core.f90.o -Lbuild/gfortran_358323723C01102E -o build/gfortran_358323723C01102E/libmytest.so
[ 50%] libmytest.so done.
- the compilation of the executable also fails. It is only linked to
libmytest.so as expected but the latter is not linked to libstdlib:
+ gfortran -cpp -Wall -Wextra -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -fPIC -fimplicit-none -Werror=implicit-interface build/gfortran_2B4944C3A077DCE8/mytest/app_main.f90.o -Lbuild/gfortran_358323723C01102E -lmytest -o build/gfortran_F92076EC7505EC5C/app/mytest
/usr/bin/ld: build/gfortran_358323723C01102E/libmytest.so: undefined reference to __stdlib_string_type_MOD_move_string_char
/usr/bin/ld: build/gfortran_358323723C01102E/libmytest.so: undefined reference to __stdlib_string_type_MOD_new_string
collect2: error: ld returned 1 exit status
[100%] mytest done
Checking the output of ldd confirms that libmytest.so is not linked to libstdlib.so.
ldd $(find ./build/gfortran* -type f -name libmytest.so)
linux-vdso.so.1 (0x00007f8627dd9000)
libgfortran.so.5 => /lib/x86_64-linux-gnu/libgfortran.so.5 (0x00007f8627a00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f8627910000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f862771a000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f8627d5e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8627ddb000)
Now, if I add stdlib as an external dependency:
name="mytest"
...
[build]
...
link="stdlib"
[library]
type="shared"
[dependencies]
stdlib="*"
...
Everything compiles fine.
+ gfortran -shared build/gfortran_2B4944C3A077DCE8/mytest/src_core.f90.o -Lbuild/gfortran_358323723C01102E -lstdlib -o build/gfortran_358323723C01102E/libmytest.so
[ 50%] libmytest.so done.
[ 50%] main.f90
...
+ gfortran -cpp -Wall -Wextra -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -fPIC -fimplicit-none -Werror=implicit-interface build/gfortran_2B4944C3A077DCE8/mytest/app_main.f90.o -Lbuild/gfortran_358323723C01102E -lmytest -lstdlib -o build/gfortran_F92076EC7505EC5C/app/mytest
[100%] mytest done.
ldd outputs
ldd $(find ./build/gfortran* -type f -name libmytest.so)
linux-vdso.so.1 (0x00007fae365ad000)
->libstdlib.so => /home/mskocic/.local/lib/libstdlib.so (0x00007fae34e00000)
libgfortran.so.5 => /lib/x86_64-linux-gnu/libgfortran.so.5 (0x00007fae34a00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fae3646f000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fae3480a000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fae36442000)
libmvec.so.1 => /lib/x86_64-linux-gnu/libmvec.so.1 (0x00007fae34d07000)
/lib64/ld-linux-x86-64.so.2 (0x00007fae365af000)
ldd $(find ./build/gfortran* -type f -name mytest)
linux-vdso.so.1 (0x00007f43eaed9000)
->libmytest.so => not found
libgfortran.so.5 => /lib/x86_64-linux-gnu/libgfortran.so.5 (0x00007f43eaa00000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f43ead9b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f43ea80a000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f43ead6e000)
/lib64/ld-linux-x86-64.so.2 (0x00007f43eaedb000)
@FedericoPerini Do you if this is the expected behavior when compiling shared libraries with fpm? Do we need to declared dependencies in the build section even if they are already declared in the dependencies section of the fpm.toml file?