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

PropertyTypeSinceDefaultDescription
allowUnresolvedSymbolsbool1.2falseSwitch 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.
architecturestring1.0qbs.architectureTarget architecture. See qbs.architecture.
debugInformationbool1.0qbs.debugInformationGenerate debug information. See qbs.debugInformation.
separateDebugInformationbool1.4false for gcc/clang, true for MSVCWhether to store debug information in an external file or bundle instead of within the binary.
definesstringList1.0undefinedList 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"']
platformDefinesstringList1.0undefinedList 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.
includePathspathList1.0undefinedList of include paths. Relative paths are considered to be relative to the .qbs product file they are used in.
systemIncludePathspathList1.0undefinedList 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.
systemRunPathsstringList1.6Auto-detected for host builds on Linux via ldconfig, ["/lib", "/usr/lib"] otherwise on Unix, empty on WindowsThe paths the dynamic linker uses on process start-up to locate dynamic libraries.
libraryPathspathList1.0undefinedList of library search paths. Relative paths are considered to be relative to the .qbs product file they are used in.
dynamicLibrariesstringList1.0undefinedList of dynamic libraries to be linked. If the library is part of your project, consider using a Depends item instead.
staticLibrariesstringList1.0undefinedList of static libraries to be linked. If the library is part of your project, consider using a Depends item instead.
prefixHeaderspathList1.0.1undefinedList of files to automatically include at the beginning of each source file in the product.
optimizationstring1.0qbs.optimizationOptimization level. See qbs.optimization.
treatWarningsAsErrorsbool1.0falseWarnings will be handled as errors and cause the build to fail.
useCPrecompiledHeader, useCxxPrecompiledHeader, useObjcPrecompiledHeader, useObjcxxPrecompiledHeaderbool1.5falseSpecifies whether to use a precompiled header for the respective language, if one is present (see below for the associated file tags).
warningLevelstring1.0"all"Specifies the warning level for the compiler - "none" or "all".
driverFlagsstringList1.6undefinedFlags that are added to all compilation and linking commands performed by the compiler driver, independently of the language.
commonCompilerFlagsstringList1.0.1undefinedFlags that are added to all compilation commands independently of the language.
compilerVersionMajorint1.4undefinedThe major version of the compiler.
compilerVersionMinorint1.4undefinedThe minor version of the compiler.
compilerVersionPatchint1.4undefinedThe patch level component of the compiler version.
assemblerFlagsstringList1.5undefinedAdditional flags for the assembler.
cppFlagsstringList1.0undefinedAdditional flags for the C preprocessor.
cFlagsstringList1.0undefinedAdditional flags for the C compiler.
cxxFlagsstringList1.0undefinedAdditional flags for the C++ compiler.
cLanguageVersionstring1.4undefinedThe 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"
cxxLanguageVersionstring1.4undefinedThe 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"
cxxStandardLibrarystring1.4undefinedThe 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++"
objcFlagsstringList1.0undefinedAdditional flags for the Objective-C compiler.
objcxxFlagsstringList1.0undefinedAdditional flags for the Objective-C++ compiler.
linkerFlagsstringList1.0undefinedAdditional 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.
assemblerNamestring1.5determined by qbs-setup-toolchainsName of the assembler binary. This is set in the build profile.
assemblerPathstring1.5determined by qbs-setup-toolchainsFull path of the assembler binary. This is set in the build profile.
compilerNamestring1.0determined by qbs-setup-toolchainsName of the main compiler binary. This is set in the build profile.
compilerPathstring1.0determined by qbs-setup-toolchainsFull 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.
compilerPathByLanguagestring to string map1.3determined by qbs-setup-toolchainsMaps file tags to full paths of compiler binaries. This is set in the build profile.
compilerWrapperstringList1.1undefinedWrapper binary and its arguments for wrapping compiler calls. This is useful for compiler wrappers like ccache and alike.
linkerNamestring1.1.1determined by qbs-setup-toolchainsName of the linker binary. This is set in the build profile.
linkerPathstring1.1.1determined by qbs-setup-toolchainsFull path of the linker binary. This is set in the build profile.
linkerWrapperstringList1.6.2undefinedWrapper binary and its arguments for wrapping linker calls. This is useful for linker wrappers as needed by Bullseye Coverage, for example.
entryPointstring1.3undefinedName of the entry point of an executable or dynamic library. If this property is undefined, the toolchain's default is used.
runtimeLibrarystring1.3.3"dynamic" for MSVC, undefined for othersType 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.

enableExceptionsbool1.5trueWhether to enable exceptions in C++ code.
exceptionHandlingModelstring1.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.
enableRttibool1.5undefinedWhether to enable runtime type information in C++ code.
enableReproducibleBuildsbool1.5falseTry 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.

Properties Specific to Apple Platforms

PropertyTypeSinceDefaultDescription
dsymutilFlagsstringList1.4.1undefinedAdditional flags for the dsymutil tool.
dsymutilPathstring1.4determined by qbs-setup-toolchainsFull path of the dsymutil binary. This is set in the build profile.
frameworkPathspathList1.0undefinedList of framework search paths. Relative paths are considered to be relative to the .qbs product file they are used in.
systemFrameworkPathspathList1.0undefinedList 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.
frameworksstringList1.0undefinedList of frameworks to be linked. If the framework is part of your project, consider using a Depends item instead.
weakFrameworksstringList1.0undefinedList of frameworks to be weakly linked. If the framework is part of your project, consider using a Depends item instead.
automaticReferenceCountingbool1.4undefinedWhether to enable Automatic Reference Counting (ARC) for Objective-C and Objective-C++ source code. If undefined, uses the compiler default (probably false).
requireAppExtensionSafeApibool1.4undefinedWhether 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).
minimumIosVersionstring1.0undefined, but may be set by generated profilesA 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.
minimumOsxVersionstring1.0.1undefined, but may be set by generated profilesDeprecated in Qbs 1.5.2. Use minimumMacosVersion instead.
minimumMacosVersionstring1.5.2undefined, but may be set by generated profilesA 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.
minimumWatchosVersionstring1.5undefined, but may be set by generated profilesA 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.
minimumTvosVersionstring1.5undefined, but may be set by generated profilesA 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

PropertyTypeSinceDefaultDescription
archiverNamestring1.0"ar"Name of the archiver binary. This is set in the build profile.
archiverPathstring1.0determined by qbs-setup-toolchainsFull path of the archiver binary. This is set in the build profile.
exportedSymbolsCheckModestring1.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".
linkerModestring1.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.
nmNamestring1.2"nm"Name of the nm binary. This is set in the build profile.
nmPathstring1.2determined by qbs-setup-toolchainsFull path of the nm binary. This is set in the build profile.
objcopyNamestring1.4"objcopy"Name of the objcopy binary. This is set in the build profile.
objcopyPathstring1.4determined by qbs-setup-toolchainsFull path of the objcopy binary. This is set in the build profile.
stripNamestring1.4"strip"Name of the strip binary. This is set in the build profile.
stripPathstring1.4determined by qbs-setup-toolchainsFull path of the strip binary. This is set in the build profile.
positionIndependentCodebool1.0undefinedGenerate position independent code. If this property is undefined, then position independent code is generated for libraries, but not for applications.
rpathsstringList1.0undefinedList of rpaths that are passed to the linker. Paths that also appear in systemRunPaths are ignored.
sonamePrefixstring1.5undefinedIf 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.

useRPathsbool1.3trueSet this property to false to prevent the linker from writing rpaths to the binary.
visibilitystring1.0"default"Visibility level for exported symbols. Possible values include: "default", "hidden", "hiddenInlines", and "minimal", which combines "hidden" and "hiddenInlines".

Properties Specific to Windows

PropertyTypeSinceDefaultDescription
generateManifestFilebool1.5.0trueSpecifies whether to auto-generate a manifest file and include it in the binary. Disable this property if you provide your own rc file.
windowsApiCharacterSetstring1.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.
minimumWindowsVersionstring1.0undefined, but may be set by generated profilesA 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

PropertyTypeSinceDefaultDescription
compilerDefinesstringList1.0undefinedList of preprocessor macros that are used for all projects that are using the current toolchain. User project files usually do not set this property.
compilerIncludePathspathList1.6determined automaticallyList 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.
compilerFrameworkPathspathList1.6determined automaticallyList 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.
compilerLibraryPathspathList1.6determined automaticallyList 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.

Relevant File Tags

TagAuto-tagged File NamesSinceDescription
"application"n/a1.0.1The 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.0Source 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, *.sx1.1.0Like "asm", but for source files that need preprocessing. This tag only has an effect with GCC-like toolchains.
"c"*.c1.0.1Source 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"*.C, *.cpp, *.cxx, *.c++, *.cc1.0.1Source 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{"c_pch_src"}, "cpp_pch_src", "objc_pch_src", "objcpp_pch_src"-1.5Files 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/a1.0.1The rule that creates dynamic libraries (typically via a linker) attaches this tag to its output artifact.
"hpp"*.h, *.H, *.hpp, *.hxx, *.h++1.0.1This 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.0This 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/a1.0.1The 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"*.m1.1.0Source 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"*.mm1.1.0Source 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.
"rc"*.rc1.1.0Files 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/a1.0.1The rule that creates static libraries (typically via a linker) attaches this tag to its output artifact.
"versionscript"-1.5.0This 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.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.