Building a Library
FoBiS.py can build both static and shared Fortran libraries using the -mklib option.
Target required
Library building always requires specifying a -target file. Only the target and its dependencies are compiled and archived.
Source layout
src/
├── mylib.f90 ← library entry point (no `program` statement)
└── utils/
└── helpers.f90mylib.f90 might look like:
module mylib
use helpers
implicit none
public :: compute
contains
function compute(x) result(y)
real, intent(in) :: x
real :: y
y = helpers_process(x)
end function
end module mylibStatic library
FoBiS.py build -t src/mylib.f90 -mklib static -o libmylib.aResult: libmylib.a in the build directory, plus *.mod files in mod/.
Shared library
FoBiS.py build -t src/mylib.f90 -mklib shared -o libmylib.so \
-cflags " -c -fPIC" -lflags " -shared"Result: libmylib.so in the build directory.
Using the library in another project
Once built, the library can be linked into another project. With -libs (full path):
FoBiS.py build -libs /path/to/libmylib.a -i /path/to/mod/Or with -ext_libs (by name):
FoBiS.py build -ext_libs mylib -dlib /path/to/ -i /path/to/mod/fobos examples
Static and shared variants
[modes]
modes = static shared
[static]
compiler = gnu
cflags = -c -O2
build_dir = ./build/
obj_dir = ./build/obj/
mod_dir = ./build/mod/
src = ./src/
target = mylib.f90
mklib = static
output = libmylib.a
[shared]
compiler = gnu
cflags = -c -fPIC -O2
lflags = -shared
build_dir = ./build/
obj_dir = ./build/obj/
mod_dir = ./build/mod/
src = ./src/
target = mylib.f90
mklib = shared
output = libmylib.soFoBiS.py build -mode static
FoBiS.py build -mode sharedConsumer project fobos
[default]
compiler = gnu
cflags = -c -O2
src = ./src/
build_dir = ./build/
libs = /path/to/libmylib.a
include = /path/to/mod/
target = main.f90
output = myappVolatile library (rebuild on change)
If the library is rebuilt externally (e.g. by CI), use -vlibs so that your project recompiles when the library changes:
FoBiS.py build -vlibs /shared/build/libmylib.a -i /shared/build/mod/See Volatile Libraries for details.
Interdependent build
For a more automated approach — where FoBiS.py build on the consumer project also rebuilds the library if its sources have changed — use -dependon:
[default]
compiler = gnu
cflags = -c -O2
src = ./src/
target = main.f90
dependon = ./libs/mylib/fobos:staticSee Interdependent Projects for details.