Link stdlib as a static library in dev stage with fpm

Hello!

I am working on a large fpm project that heavily depends on stdlib, which I am including as a metapackage.

In the release version of the project we will leave it that way, but in the development stage recompiling stdlib at each iteration is very time consuming and unnecessary. Therefore, I want to include stdlib as an external static library in the dev branch of the project.

Is this the way forward or is there another solution, such as to selectively compile code when necessary?

I have cloned stdlib-fpm and installed it (by changing the corresponding flag in fpm.toml).

But when I try to compile my project, I get an error that the source files cannot be found.
fpm.toml

...
[build]
auto-executables = true
auto-tests = true
auto-examples = true
module-naming = false
external-modules = ["mpi_f08", "stdlib"]
...

Compilation:

fpm build --flag "-I$HOME/.local/include"

or

fpm build --flag "-I$HOME/.local/include" --link-flag "-L$HOME/.local/lib -lstdlib"

with the error

<ERROR> *cmd_build* Target error: Unable to find source for module dependency: "stdlib_optval" used by "././src/BaseKrylov.f90"
STOP 1

I have checked that the *mod files are located in the include path and the libstdlib.a file is in the library path.

I do not have these issues with the mpi library, which is found without problems using

fpm build --compiler "mpif90" --flag "-DMPI -I$MPI_include"

(with stdlib as a metapackage to isolate mpi_f08 and the appropriate def for MPI_include)

What am I missing in the installation/compilation pipeline? Thanks for any advice as to what I should try to link the library.

1 Like