My project has external library dependencies and I am using waf scripts to build it - C, C++.
I am trying to build static library which will have all the dependent libraries statically linked. For example, I use this to build dynamic shared object:
bld.program(features = 'c cxx cxxshlib'
, target = 'program'
, source = sources
, use = libs_list)
Shared object will have all the dependent libraries (specified with libs_list) linked.
However, static library:
bld.program(features = 'c cxx cxxstlib'
, target = 'program'
, cppflags = '-DSTATIC_LIB'
, source = sources
, use = libs_list)
will not. Is there a way to overcome this? Or do I need to do this manually in post build function?
Prior to waf 1.8, the static libraries used to share the same behavior of recursive dependencies with shared objects. Due to static libs order of use, I think this was removed. That means that if your shared object is dependant of other libs, waf will automatically include them, but for static libs, you have to list all the libraries in correct order yourself.
Here is how 'uselib' should be used :
def configure(conf):
# for libs that have a pkg-config
conf.check_cfg("expat", args = ["--libs"])
# to use /some/path/libotherextlib.a or .so
conf.env.LIB_OEL = ['otherextlib']
conf.env.LIBPATH_OEL = ["/some/path"]
def build(bld):
lib_lists = ["expat", "oel"]
bld.shlib(target = 'myshlib', source = sources, use = libs_list)
bld.stlib(target = 'mystlib', source = sources, use = libs_list)
To modularize you can do :
bld.objects(source = sources1, name = "module1")
bld.objects(source = sources2, name = "module2")
modules = ["module1", "module2"]
bld.stlib(target = 'mystlib', use = modules)
bld.shlib(target = 'myshlib', use = modules)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With