Table of Contents
The c/c++ builds consist in transforming source files into object files, and to assemble the object files at the end. In theory a single programming language should be sufficient for writing any application, but in practice slight variations exist:
The construction of c/c++ applications can be quite complicated, and several measures must be taken to ensure coherent interaction with new compilation rules. The canonical code for a task generator building a c/c++ application is the following:
def build(bld): t = bld.new_task_gen( features = 'cc cprogram',source = 'main.c',
target = 'appname',
includes = '.',
install_path = '${SOME_PATH}/bin',
defines = ['LINUX=1', 'BIDULE'],
ccflags = ['-O2', '-Wall'],
lib = ['m'],
libpath = ['/usr/lib'] ) if sys.platform != 'win32': t.rpath = '/usr/lib'
![]()
Task generator declaration; each element in the list represent a feature; it is possible to add several languages at once (ocaml and c++ for example), but the one of cstaticlib, cshlib or cprogram must be chosen. | |
List of source, it may be either a python list, or a string containing the file names separated with spaces. This list may contain file names of different extensions to make hybrid applications. | |
Target name, it is concerted to the name of the binary name.so or name.exe depending on the platform and the features. | |
List of include paths, it may be either a python list, or a string containing the paths separated by spaces. The paths are used for both the command-line and for finding the implicit dependencies (headers). In general, include paths must be relative to the wscript file and given explicitly. See the section called “The include system”. | |
Installation directory, this is where to install the library or program produced. The ${} expression is a reference to a variable to be extracted from tgen.env. By default it is set to ${PREFIX}/bin for programs and ${PREFIX}/lib for libraries. To disable the installation, set it to None. | |
Command-line defines: list of defines to add to the command-line with the -D prefix. To reduce the size of the command-line, it is possible to use a configuration header, see the following section for more details. | |
Command-line compilation flags, for the c++ language the attribute is called cxxflags | |
Shared libraries may be given directly (use staticlib and staticlibpath for static libraries) | |
Additional pararameters may be added from a task generator reference. The next section describes a technique to gather the conditions into the configuration section. |