To link a library against another one created in the same Waf project, the attribute uselib_local may be used. The include paths, the link path and the library name are automatically exported, and the dependent binary is recompiled when the library changes:
def build(bld): staticlib = bld.new_task_gen( features = 'cc cstaticlib',source = 'test_staticlib.c', target = 'teststaticlib', export_incdirs = '.')
main = bld.new_task_gen( features = 'cc cprogram',
source = 'main.c', target = 'test_c_program', includes = '.', uselib_local = 'teststaticlib')
![]()
A static library | |
Include paths to export for use with uselib_local (include paths are not added automatically). These folders are taken relatively to the current target. | |
A program using the static library declared previously | |
A list of references to existing libraries declared in the project (either a python list or a string containing the names space-separated) |
To link an application against various system libraries, several compilation flags and link flags must be given at once. To reduce the maintenance, a system called uselib can be used to give all the flags at the same time:
def configure(conf): conf.env['CCFLAGS_TEST'] = '-O2'conf.env['LINKFLAGS_TEST'] = '-g' def build(bld): staticlib = bld.new_task_gen( features = 'cc cstaticlib', source = 'test_staticlib.c', target = 'teststaticlib', uselib = 'TEST')
![]()
Declare a few variables during the configuration, the variables follow the convention VAR_NAME | |
Add all the VAR_NAME corresponding to the uselib NAME, which is 'TEST' in this example |
The variables used for c/c++ are the following: STATICLIB, LIB, LIBPATH, LINKFLAGS, RPATH, CXXFLAGS, CCFLAGS, CPPPATH, CPPFLAGS, CXXDEFINES, FRAMEWORK, FRAMEWORKPATH, CXXDEPS. The uselib is similar to the cascading style sheet (CSS) principle.