Qbs Manual | List of Modules | Module cpp

Qbs 1.9.1

# Module cpp

The `cpp` module contains the properties and rules for toolchains of the C/C++ family. On Apple platforms this includes support for Objective-C/C++.

## General Properties

Property | Type | Since | Default | Description
--- | --- | --- | --- | ---
allowUnresolvedSymbols | `bool` | 1.2 | `false` | Switch this on if you want the linking step to succeed even if the resulting binary contains unresolved symbols. Normally this makes little sense, but in special cases it is possible that the respective symbols will be available at load time even if they are not present during linking.
architecture | `string` | 1.0 | `qbs.architecture` | Target architecture. See `qbs.architecture`.
endianness | `string` | 1.9 | Specifies the endianness of the target platform's processor architecture (`"big"` or `"little"`). The value is automatically detected from the compiler's defaults, but can also be manually set in order to select a specific endianness when targeting bi-endian architectures like MIPS and PowerPC.
debugInformation | `bool` | 1.0 | `qbs.debugInformation` | Generate debug information. See `qbs.debugInformation`.
combineCSources | `bool` | 1.8 | `false` | Enabling this property on a product instructs the file tagger to attach the tag `"c.combine"` to C sources, rather than `"c"`. As a result, all C sources of the product will be combined into a single file which is then compiled. This can speed up initial compilation significantly, but is of course detrimental in the context of incremental builds. Also, perfectly legal code may fail to compile with this option due to the merging of translation units. If you want to enable this property in a product that has some sources which cannot be merged, you need to put these into a dedicated group and set their file tag to `"c"`, overriding the file tagger.

Note: Module properties set on specific source files (that is, at the Group level) will not be taken into account when building the combined file. You either need to set these properties at the product level instead or prevent the respective files from getting combined via the mechanism described above.

combineCxxSources | `bool` | 1.8 | `false` | Like `combineCSources`, but for C++. The relevant file tags are `"cpp"` and `"cpp.combine"`.
combineObjcSources | `bool` | 1.8 | `false` | Like `combineCSources`, but for Objective-C. The relevant file tags are `"objc"` and `"objc.combine"`.
combineObjcxxSources | `bool` | 1.8 | `false` | Like `combineCSources`, but for Objective-C++. The relevant file tags are `"objcpp"` and `"objcpp.combine"`.
separateDebugInformation | `bool` | 1.4 | `false` for gcc/clang, `true` for MSVC | Whether to store debug information in an external file or bundle instead of within the binary.
defines | `stringList` | 1.0 | `undefined` | List of preprocessor macros that gets passed to the compiler. To set macro values use the following syntax: `cpp.defines: ["USE_COLORS=1", 'COLOR_STR="blanched almond"']`
platformDefines | `stringList` | 1.0 | `undefined` | List of preprocessor macros that are used for all projects that are built for the current target platform. User project files usually do not set this property.
includePaths | `pathList` | 1.0 | `undefined` | List of include paths. Relative paths are considered to be relative to the .qbs product file they are used in.
systemIncludePaths | `pathList` | 1.0 | `undefined` | List of include paths that are passed as system include paths to the compiler. For header files in those paths warnings will be ignored. Relative paths are considered to be relative to the .qbs product file they are used in.
systemRunPaths | `stringList` | 1.6 | Auto-detected for host builds on Linux via `ldconfig`, `["/lib", "/usr/lib"]` otherwise on Unix, empty on Windows | The paths the dynamic linker uses on process start-up to locate dynamic libraries.
libraryPaths | `pathList` | 1.0 | `undefined` | List of library search paths. Relative paths are considered to be relative to the .qbs product file they are used in.
dynamicLibraries | `stringList` | 1.0 | `undefined` | List of dynamic libraries to be linked. If the library is part of your project, consider using a Depends item instead.
staticLibraries | `stringList` | 1.0 | `undefined` | List of static libraries to be linked. If the library is part of your project, consider using a Depends item instead.
prefixHeaders | `pathList` | 1.0.1 | `undefined` | List of files to automatically include at the beginning of each source file in the product.
optimization | `string` | 1.0 | `qbs.optimization` | Optimization level. See `qbs.optimization`.
treatWarningsAsErrors | `bool` | 1.0 | `false` | Warnings will be handled as errors and cause the build to fail.
useCPrecompiledHeader, useCxxPrecompiledHeader, useObjcPrecompiledHeader, useObjcxxPrecompiledHeader | `bool` | 1.5 | `true` | Specifies whether to use a precompiled header for the respective language, if one is present (see below for the associated file tags).
warningLevel | `string` | 1.0 | `"all"` | Specifies the warning level for the compiler - `"none"` or `"all"`.
driverFlags | `stringList` | 1.6 | undefined | Flags that are added to all compilation and linking commands performed by the compiler driver, independently of the language.
commonCompilerFlags | `stringList` | 1.0.1 | undefined | Flags that are added to all compilation commands independently of the language.
compilerVersionMajor | `int` | 1.4 | undefined | The major version of the compiler.
compilerVersionMinor | `int` | 1.4 | undefined | The minor version of the compiler.
compilerVersionPatch | `int` | 1.4 | undefined | The patch level component of the compiler version.
assemblerFlags | `stringList` | 1.5 | undefined | Additional flags for the assembler.
cppFlags | `stringList` | 1.0 | undefined | Additional flags for the C preprocessor.
cFlags | `stringList` | 1.0 | undefined | Additional flags for the C compiler.
cxxFlags | `stringList` | 1.0 | undefined | Additional flags for the C++ compiler.
cLanguageVersion | `string` | 1.4 | undefined | The version of the C standard with which the code must comply. If this property is set, corresponding compiler and/or linker flags will be added, depending on the toolchain. If the value is left undefined, the compiler default will be used. Possible values include: `"c89"`, `"c99"`, `"c11"`
cxxLanguageVersion | `string` | 1.4 | undefined | The version of the C++ standard with which the code must comply. If this property is set, corresponding compiler and/or linker flags will be added, depending on the toolchain. If the value is left undefined, the compiler default will be used. Possible values include: `"c++98"`, `"c++11"`, `"c++14"`
cxxStandardLibrary | `string` | 1.4 | undefined | The C++ standard library to link to. If this property is set, corresponding compiler and/or linker flags will be added, assuming the value is valid for the current toolchain. If the value is left undefined, the compiler default will be used. Possible values include: `"libstdc++"`, `"libc++"`
objcFlags | `stringList` | 1.0 | undefined | Additional flags for the Objective-C compiler.
objcxxFlags | `stringList` | 1.0 | undefined | Additional flags for the Objective-C++ compiler.
linkerFlags | `stringList` | 1.0 | undefined | Additional flags for the linker. These flags should not be escaped using the -Wl or -Xlinker syntaxes, as Qbs will do this automatically based on the linker being used. See cpp.linkerMode for additional information.
assemblerName | `string` | 1.5 | determined by qbs-setup-toolchains | Name of the assembler binary. This is set in the build profile.
assemblerPath | `string` | 1.5 | determined by qbs-setup-toolchains | Full path of the assembler binary. This is set in the build profile.
compilerName | `string` | 1.0 | determined by qbs-setup-toolchains | Name of the main compiler binary. This is set in the build profile.
compilerPath | `string` | 1.0 | determined by qbs-setup-toolchains | Full path of the main compiler binary. This is set in the build profile. If the toolchain provides different compilers for different languages, then `compilerPathByLanguage` is used.
compilerPathByLanguage | `string` to `string` map | 1.3 | determined by qbs-setup-toolchains | Maps file tags to full paths of compiler binaries. This is set in the build profile.
compilerWrapper | `stringList` | 1.1 | `undefined` | Wrapper binary and its arguments for wrapping compiler calls. This is useful for compiler wrappers like ccache and alike.
linkerName | `string` | 1.1.1 | determined by qbs-setup-toolchains | Name of the linker binary. This is set in the build profile.
linkerPath | `string` | 1.1.1 | determined by qbs-setup-toolchains | Full path of the linker binary. This is set in the build profile.
linkerWrapper | `stringList` | 1.6.2 | `undefined` | Wrapper binary and its arguments for wrapping linker calls. This is useful for linker wrappers as needed by Bullseye Coverage, for example.
entryPoint | `string` | 1.3 | `undefined` | Name of the entry point of an executable or dynamic library. If this property is undefined, the toolchain's default is used.
runtimeLibrary | `string` | 1.3.3 | `"dynamic"` for MSVC, `undefined` for others | Type of the used runtime library. Accepted values are `"static"` and `"dynamic"`. If this property is set to `undefined`, then the default runtime library of the toolchain is used. Note: For MSVC the default value is `"dynamic"`. Note: At the moment this property is only functional for MSVC.
enableExceptions | `bool` | 1.5 | `true` | Whether to enable exceptions in C++ code.
exceptionHandlingModel | `string` | 1.5 | `"default"` | The exception handling model to use. For MSVC, this can be `"default"`, `"seh"` or `"externc"`. For all other compilers, `"default"` indicates the default or only exception handling model.
enableRtti | `bool` | 1.5 | `undefined` | Whether to enable runtime type information in C++ code.
enableReproducibleBuilds | `bool` | 1.5 | `false` | Try to generate reproducible object files. Some compilers (notably gcc) use random numbers for generating symbol names that have to be different in every compilation unit. This is avoided by setting this property to `true`.
treatSystemHeadersAsDependencies | `bool` | 1.8 | `false` | If this property is enabled, then included header files found via `systemIncludePaths`, `distributionIncludePaths` or `compilerIncludePaths` will be added to the dependencies of the respective object file. This means that modification of such header files (or any of the headers they include) will cause recompilation.

## Properties Specific to Apple Platforms

Property | Type | Since | Default | Description
--- | --- | --- | --- | ---
dsymutilFlags | `stringList` | 1.4.1 | undefined | Additional flags for the dsymutil tool.
dsymutilPath | `string` | 1.4 | determined by qbs-setup-toolchains | Full path of the dsymutil binary. This is set in the build profile.
lipoPath | `string` | 1.9 | determined automatically | Full path of the lipo binary.
frameworkPaths | `pathList` | 1.0 | `undefined` | List of framework search paths. Relative paths are considered to be relative to the .qbs product file they are used in.
systemFrameworkPaths | `pathList` | 1.0 | `undefined` | List of framework search paths. Relative paths are considered to be relative to the .qbs product file they are used in. Header files in frameworks in those paths will not cause warnings.
frameworks | `stringList` | 1.0 | `undefined` | List of frameworks to be linked. If the framework is part of your project, consider using a Depends item instead.
weakFrameworks | `stringList` | 1.0 | `undefined` | List of frameworks to be weakly linked. If the framework is part of your project, consider using a Depends item instead.
automaticReferenceCounting | `bool` | 1.4 | `undefined` | Whether to enable Automatic Reference Counting (ARC) for Objective-C and Objective-C++ source code. If `undefined`, uses the compiler default (probably `false`).
requireAppExtensionSafeApi | `bool` | 1.4 | `undefined` | Whether to enforce the use of only app-extension-safe APIs on Apple platforms. This is necessary for building Application Extensions in OS X Yosemite and iOS 8 and above. If `undefined`, uses the compiler and linker defaults (probably `false`).
minimumIosVersion | `string` | 1.0 | undefined, but may be set by generated profiles | A version number in the format [major].[minor] indicating the earliest version of iOS that the product should run on. Passes -miphoneos-version-min=<version> to the compiler. If undefined, compiler defaults will be used.
minimumOsxVersion | `string` | 1.0.1 | undefined, but may be set by generated profiles | Deprecated in Qbs 1.5.2. Use `minimumMacosVersion` instead.
minimumMacosVersion | `string` | 1.5.2 | undefined, but may be set by generated profiles | A version number in the format [major].[minor] indicating the earliest version of macOS that the product should run on. Passes -mmacosx-version-min=<version> to the compiler. If undefined, compiler defaults will be used.
minimumWatchosVersion | `string` | 1.5 | undefined, but may be set by generated profiles | A version number in the format [major].[minor] indicating the earliest version of Apple watchOS that the product should run on. If undefined, compiler defaults will be used.
minimumTvosVersion | `string` | 1.5 | undefined, but may be set by generated profiles | A version number in the format [major].[minor] indicating the earliest version of Apple tvOS that the product should run on. If undefined, compiler defaults will be used.

## Properties Specific to Unix Platforms

Property | Type | Since | Default | Description
--- | --- | --- | --- | ---
archiverName | `string` | 1.0 | `"ar"` | Name of the archiver binary. This is set in the build profile.
archiverPath | `string` | 1.0 | determined by qbs-setup-toolchains | Full path of the archiver binary. This is set in the build profile.
exportedSymbolsCheckMode | `string` | 1.4.1 | "ignore-undefined" | Controls how Qbs determines whether an updated dynamic library causes relinking of dependents. The default value is `"ignore-undefined"`, which means that undefined symbols being added or removed do not cause any relinking. If that should happen, for example because dependent products are linked with an option such as `"--no-undefined"`, then this property can be set to `"strict"`.
linkerMode | `string` | 1.6 | "automatic" | Controls whether to automatically use an appropriate compiler frontend in place of the system linker when linking binaries. The default is `"automatic"`, which chooses either the C++ compiler, C compiler, or system linker specified by the `linkerName` and `linkerPath` properties, depending on the type of object files present on the linker command line. `"manual"` allows you to explicitly specify the linker using the `linkerName` and `linkerPath` properties.
nmName | `string` | 1.2 | `"nm"` | Name of the nm binary. This is set in the build profile.
nmPath | `string` | 1.2 | determined by qbs-setup-toolchains | Full path of the nm binary. This is set in the build profile.
objcopyName | `string` | 1.4 | `"objcopy"` | Name of the objcopy binary. This is set in the build profile.
objcopyPath | `string` | 1.4 | determined by qbs-setup-toolchains | Full path of the objcopy binary. This is set in the build profile.
stripName | `string` | 1.4 | `"strip"` | Name of the strip binary. This is set in the build profile.
stripPath | `string` | 1.4 | determined by qbs-setup-toolchains | Full path of the strip binary. This is set in the build profile.
positionIndependentCode | `bool` | 1.0 | `undefined` | Generate position independent code. If this property is `undefined`, then position independent code is generated for libraries, but not for applications.
rpaths | `stringList` | 1.0 | `undefined` | List of rpaths that are passed to the linker. Paths that also appear in `systemRunPaths` are ignored.
sonamePrefix | `string` | 1.5 | `undefined` | If defined, the value of this variable is used as a path to be prepended to the built shared library's `SONAME` identifier. The `SONAME` (`LC_ID_DYLIB` on Apple platforms, `DT_SONAME` on other Unix-like platforms) is the identifier that the dynamic linker will later use to reference the library. In general, this reference may be a library name or full library path.

On Apple platforms, the path may contain the following placeholders:

- @rpath - Expands to paths defined by LC_RPATH Mach-O commands in the current process executable or the referring libraries.
- @executable_path - Expands to the current process executable location.
- @loader_path - Expands to the referring executable or library location.

In most cases, using `@rpath` is sufficient and recommended. However, the prefix may be also specified using different placeholders, or an absolute path.

For more information, see the dyld documentation on dynamic library install names.

soVersion | `string` | 1.7 | Major part of `product.version` if a version is set, otherwise the empty string | The version to be appended to the soname in ELF shared libraries.
useRPaths | `bool` | 1.3 | `true` | Set this property to `false` to prevent the linker from writing rpaths to the binary.
useRPathLink | `bool` | 1.8 | `true` on non-Darwin Unix platforms or when targeting macOS 10.4.x and older. | Use the `-rpath-link` linker option for transitive shared objects.
visibility | `string` | 1.0 | `"default"` | Visibility level for exported symbols. Possible values include: `"default"`, `"hidden"`, `"hiddenInlines"`, and `"minimal"`, which combines `"hidden"` and `"hiddenInlines"`.

## Properties Specific to Windows

Property | Type | Since | Default | Description
--- | --- | --- | --- | ---
generateManifestFile | `bool` | 1.5.0 | `true` | Specifies whether to auto-generate a manifest file and include it in the binary. Disable this property if you provide your own rc file.
windowsApiCharacterSet | `string` | 1.0.1 | `"unicode"` | Specifies the character set used in the Win32 API. "unicode" will define the preprocessor symbols UNICODE and _UNICODE, "mbcs" will define _MBCS, and setting the value to undefined will use the default character set.
minimumWindowsVersion | `string` | 1.0 | undefined, but may be set by generated profiles | A version number in the format [major].[minor] indicating the earliest version of Windows that the product should run on. Defines WINVER, _WIN32_WINNT, and _WIN32_WINDOWS, and applies a version number to the linker flags /SUBSYSTEM and /OSVERSION for MSVC or --major-subsystem-version, --minor-subsystem-version, --major-os-version and --minor-os-version for MinGW. If undefined, compiler defaults will be used.

## Advanced Properties

Property | Type | Since | Default | Description
--- | --- | --- | --- | ---
alwaysUseLipo | {bool} | 1.9 | `false` | Whether to always use lipo when combining Mach-O output files on Apple platforms, even if there is only one CPU architecture. The should not normally need to be changed.
compilerDefines | `stringList` | 1.0 | `undefined` | List of preprocessor macros that are used for all projects that are using the current toolchain. User project files usually do not set this property.
compilerIncludePaths | `pathList` | 1.6 | determined automatically | List of #include search paths that are used for all projects that are using the current toolchain. Determined automatically by probing the compiler. User project files usually do not set this property.
compilerFrameworkPaths | `pathList` | 1.6 | determined automatically | List of framework search paths that are used for all projects that are using the current toolchain. Determined automatically by probing the compiler. User project files usually do not set this property.
compilerLibraryPaths | `pathList` | 1.6 | determined automatically | List of library search paths that are used for all projects that are using the current toolchain. Determined automatically by probing the compiler. User project files usually do not set this property.
distributionFrameworkPaths | `pathList` | 1.8 | `undefined` | List of distribution-specific framework search paths, prioritized after `systemFrameworkPaths`. Intended for use by module authors implementing support for new operating systems/distributions. User project files should not set this property.
distributionIncludePaths | `pathList` | 1.8 | `undefined` | List of distribution-specific include paths that are passed as system include paths to the compiler, prioritized after `systemIncludePaths`. Intended for use by module authors implementing support for new operating systems/distributions. User project files should not set this property.
distributionLibraryPaths | `pathList` | 1.8 | `undefined` | List of distribution-specific library search paths, prioritized after `systemLibraryPaths`. Intended for use by module authors implementing support for new operating systems/distributions. User project files should not set this property.

## Dependency Parameters

Parameter | Type | Since | Default | Description
--- | --- | --- | --- | ---
`link` | `bool` | 1.9 | undefined | If `false`, the dependency will not be linked, even if it is a valid input for a linker rule. This property affects library dependencies only.
`linkWholeArchive` | `bool` | 1.9 | undefined | If `true`, then if the dependency is a static library, all of its objects will be pulled into target binary, even if their symbols do not appear to be used. This parameter is mainly useful when creating a dynamic library from static libraries.
`symbolLinkMode` | `string` | 1.9 | undefined | Attribute specifying how the library or framework will be linked. May contain the values: "weak", "lazy", "reexport", and "upward"; refer to the Apple ld64 man page for full details. `undefined` uses normal linking. Currently only applies when linking for Apple platforms.

## Relevant File Tags

Tag | Auto-tagged File Names | Since | Description
--- | --- | --- | ---
`"application"` | n/a | 1.0.1 | The rule that creates executable files (typically via a linker) attaches this tag to its output artifact.
`"asm"` | `*.s` (for GCC-like toolchains), `*.asm` (for MSVC) | 1.1.0 | Source files with this tag serve as inputs to a rule invoking the toolchain's assembler. One object file is generated for each such file.
`"asm_cpp"` | `*.S`, `*.sx` | 1.1.0 | Like `"asm"`, but for source files that need preprocessing. This tag only has an effect with GCC-like toolchains.
`"c"` | `*.c` (if `combineCSources` is not enabled) | 1.0.1 | Source files with this tag serve as inputs to a rule invoking the toolchain's C compiler. One object file is generated for each such file.
`"c.combine"` | `*.c` (if `combineCSources` is enabled) | 1.8 | Source files with this tag serve as inputs to a rule combining them into a single C file, which will then be compiled.
`"cpp"` | `*.C`, `*.cpp`, `*.cxx`, `*.c++`, `*.cc` (if `combineCxxSources` is not enabled) | 1.0.1 | Source files with this tag serve as inputs to a rule invoking the toolchain's C++ compiler. One object file is generated for each such file.
`"cpp.combine"` | `*.C`, `*.cpp`, `*.cxx`, `*.c++`, `*.cc` (if `combineCxxSources` is enabled) | 1.8 | Source files with this tag serve as inputs to a rule combining them into a single C++ file, which will then be compiled.
`"c_pch_src"`, `"cpp_pch_src"`, `"objc_pch_src"`, `"objcpp_pch_src"` | - | 1.5 | Files with this tag will be turned into precompiled headers for C, C++, Objective-C and Objective-C++, respectively. There can be only one such file per product and language.
`"dynamiclibrary"` | n/a | 1.0.1 | The rule that creates dynamic libraries (typically via a linker) attaches this tag to its output artifact.
`"hpp"` | `*.h`, `*.H`, `*.hpp`, `*.hxx`, `*.h++` | 1.0.1 | This tag is used for header files (C, C++, Objective-C and Objective-C++). No rule in this module generates output artifacts from such files directly, but the compiler rule will have a dependency on all rules that create such files.
`"linkerscript"` | - | 1.5.0 | This tag is used for `ld` linker scripts. You can provide such a file if you need to replace the default linker script. This file tag only has an effect with GCC-like toolchains. The linker needs to be `ld`-compatible.
`"obj"` | n/a | 1.0.1 | The rule that creates object files (typically via a compiler) attaches this tag to its output artifacts. Such files are usually intermediate artifacts of the build process and rarely need to be referenced in project files.
`"objc"` | `*.m` (if `combineObjcSources` is not enabled) | 1.1.0 | Source files with this tag serve as inputs to a rule invoking the toolchain's Objective-C compiler. One object file is generated for each such file.
`"objc.combine"` | `*.m` (if `combineObjcSources` is enabled) | 1.8 | Source files with this tag serve as inputs to a rule combining them into a single Objective-C file, which will then be compiled.
`"objcpp"` | `*.mm` (if `combineObjcxxSources` is not enabled) | 1.1.0 | Source files with this tag serve as inputs to a rule invoking the toolchain's Objective-C++ compiler. One object file is generated for each such file.
`"objcpp.combine"` | `*.mm` (if `combineObjcxxSources` is enabled) | 1.8 | Source files with this tag serve as inputs to a rule combining them into a single Objective-C++ file, which will then be compiled.
`"rc"` | `*.rc` | 1.1.0 | Files with this tag serve as inputs to the Windows resource compiler. One object file is generated for each such file. The tag has no effect on target platforms other than Windows.
`"staticlibrary"` | n/a | 1.0.1 | The rule that creates static libraries (typically via a linker) attaches this tag to its output artifact.
`"versionscript"` | - | 1.5.0 | This tag is used for `ld` linker scripts. You can provide such a file if you need fine-grained control over the symbols present in a shared library. This file tag only has an effect with GCC-like toolchains. The linker needs to be `ld`-compatible.