How to build static libraries from shared objects
It is sometimes necessary to build and redistribute static libraries that for future use in shared libraries. On Linux -fPIC
is usually passed to the arguments of the compiler. The first attempts at writing a portable wscript file typically resemble the following:
The problem with this approach is that both -fPIC
and -shared
flags are then propagated to all downstream targets, with the annoying side effect of silently turning programs into shared libraries. Flag propagation can be easily stopped by replacing use
by uselib
:
While this works, the code above is more difficult to understand as the uselib
keyword is less frequently used. The best approach may be to declare explicitly the flags instead. In this case it is sufficient to specify the cflags
(cxxflags
in C++ or fcflags
in Fortran):