146035553Spatrick.. _BuildingLibcxx: 246035553Spatrick 346035553Spatrick=============== 446035553SpatrickBuilding libc++ 546035553Spatrick=============== 646035553Spatrick 746035553Spatrick.. contents:: 846035553Spatrick :local: 946035553Spatrick 1046035553Spatrick.. _build instructions: 1146035553Spatrick 1276d0caaeSpatrickThe instructions on this page are aimed at vendors who ship libc++ as part of an 1376d0caaeSpatrickoperating system distribution, a toolchain or similar shipping vehicules. If you 1476d0caaeSpatrickare a user merely trying to use libc++ in your program, you most likely want to 1576d0caaeSpatrickrefer to your vendor's documentation, or to the general documentation for using 1676d0caaeSpatricklibc++ :ref:`here <using-libcxx>`. 1746035553Spatrick 1846035553Spatrick.. warning:: 1976d0caaeSpatrick If your operating system already provides libc++, it is important to be careful 2076d0caaeSpatrick not to replace it. Replacing your system's libc++ installation could render it 2176d0caaeSpatrick non-functional. Use the CMake option ``CMAKE_INSTALL_PREFIX`` to select a safe 2276d0caaeSpatrick place to install libc++. 2376d0caaeSpatrick 2476d0caaeSpatrick 2576d0caaeSpatrickThe default build 2676d0caaeSpatrick================= 2776d0caaeSpatrick 28*4bdff4beSrobertThe default way of building libc++, libc++abi and libunwind is to root the CMake 29*4bdff4beSrobertinvocation at ``<monorepo>/runtimes``. While those projects are under the LLVM 30*4bdff4beSrobertumbrella, they are different in nature from other build tools, so it makes sense 31*4bdff4beSrobertto treat them as a separate set of entities. The default build can be achieved 32*4bdff4beSrobertwith the following CMake invocation: 3346035553Spatrick 3446035553Spatrick.. code-block:: bash 3546035553Spatrick 3646035553Spatrick $ git clone https://github.com/llvm/llvm-project.git 3746035553Spatrick $ cd llvm-project 3876d0caaeSpatrick $ mkdir build 39*4bdff4beSrobert $ cmake -G Ninja -S runtimes -B build -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" # Configure 40*4bdff4beSrobert $ ninja -C build cxx cxxabi unwind # Build 41*4bdff4beSrobert $ ninja -C build check-cxx check-cxxabi check-unwind # Test 42*4bdff4beSrobert $ ninja -C build install-cxx install-cxxabi install-unwind # Install 4346035553Spatrick 4476d0caaeSpatrick.. note:: 4576d0caaeSpatrick See :ref:`CMake Options` below for more configuration options. 4646035553Spatrick 47*4bdff4beSrobertAfter building the various ``install-XXX`` targets, shared libraries for libc++, libc++abi and 48*4bdff4beSrobertlibunwind should now be present in ``<CMAKE_INSTALL_PREFIX>/lib``, and headers in 49*4bdff4beSrobert``<CMAKE_INSTALL_PREFIX>/include/c++/v1``. See :ref:`using an alternate libc++ installation 50*4bdff4beSrobert<alternate libcxx>` for information on how to use this libc++ over the default one. 5146035553Spatrick 52*4bdff4beSrobertIn the default configuration, the runtimes will be built using the compiler available by default 53*4bdff4beSroberton your system. Of course, you can change what compiler is being used with the usual CMake 54*4bdff4beSrobertvariables. If you wish to build the runtimes from a just-built Clang, the bootstrapping build 55*4bdff4beSrobertexplained below makes this task easy. 5646035553Spatrick 5776d0caaeSpatrick 5876d0caaeSpatrickBootstrapping build 5976d0caaeSpatrick=================== 6076d0caaeSpatrick 61*4bdff4beSrobertIt is possible to build Clang and then build the runtimes using that just-built compiler in a 62*4bdff4beSrobertsingle CMake invocation. This is usually the correct way to build the runtimes when putting together 63*4bdff4beSroberta toolchain, or when the system compiler is not adequate to build them (too old, unsupported, etc.). 64*4bdff4beSrobertTo do this, use the following CMake invocation, and in particular notice how we're now rooting the 65*4bdff4beSrobertCMake invocation at ``<monorepo>/llvm``: 6646035553Spatrick 6746035553Spatrick.. code-block:: bash 6846035553Spatrick 6976d0caaeSpatrick $ mkdir build 7076d0caaeSpatrick $ cmake -G Ninja -S llvm -B build -DLLVM_ENABLE_PROJECTS="clang" \ # Configure 71*4bdff4beSrobert -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind" \ 7276d0caaeSpatrick -DLLVM_RUNTIME_TARGETS="<target-triple>" 7376d0caaeSpatrick $ ninja -C build runtimes # Build 7476d0caaeSpatrick $ ninja -C build check-runtimes # Test 7576d0caaeSpatrick $ ninja -C build install-runtimes # Install 7646035553Spatrick 77*4bdff4beSrobert.. note:: 78*4bdff4beSrobert This type of build is also commonly called a "Runtimes build", but we would like to move 79*4bdff4beSrobert away from that terminology, which is too confusing. 8046035553Spatrick 8176d0caaeSpatrickSupport for Windows 8276d0caaeSpatrick=================== 8346035553Spatrick 8476d0caaeSpatricklibcxx supports being built with clang-cl, but not with MSVC's cl.exe, as 8576d0caaeSpatrickcl doesn't support the ``#include_next`` extension. Furthermore, VS 2017 or 8676d0caaeSpatricknewer (19.14) is required. 8776d0caaeSpatrick 8876d0caaeSpatricklibcxx also supports being built with clang targeting MinGW environments. 8946035553Spatrick 9046035553SpatrickCMake + Visual Studio 9176d0caaeSpatrick--------------------- 9246035553Spatrick 9346035553SpatrickBuilding with Visual Studio currently does not permit running tests. However, 9446035553Spatrickit is the simplest way to build. 9546035553Spatrick 9646035553Spatrick.. code-block:: batch 9746035553Spatrick 98*4bdff4beSrobert > cmake -G "Visual Studio 16 2019" -S runtimes -B build ^ 9976d0caaeSpatrick -T "ClangCL" ^ 100*4bdff4beSrobert -DLLVM_ENABLE_RUNTIMES=libcxx ^ 10146035553Spatrick -DLIBCXX_ENABLE_SHARED=YES ^ 102*4bdff4beSrobert -DLIBCXX_ENABLE_STATIC=NO 10376d0caaeSpatrick > cmake --build build 10446035553Spatrick 10576d0caaeSpatrickCMake + ninja (MSVC) 10676d0caaeSpatrick-------------------- 10746035553Spatrick 10846035553SpatrickBuilding with ninja is required for development to enable tests. 10976d0caaeSpatrickA couple of tests require Bash to be available, and a couple dozens 11076d0caaeSpatrickof tests require other posix tools (cp, grep and similar - LLVM's tests 11176d0caaeSpatrickrequire the same). Without those tools the vast majority of tests 11276d0caaeSpatrickcan still be ran successfully. 11376d0caaeSpatrick 11476d0caaeSpatrickIf Git for Windows is available, that can be used to provide the bash 11576d0caaeSpatrickshell by adding the right bin directory to the path, e.g. 11676d0caaeSpatrick``set PATH=%PATH%;C:\Program Files\Git\usr\bin``. 11776d0caaeSpatrick 11876d0caaeSpatrickAlternatively, one can also choose to run the whole build in a MSYS2 11976d0caaeSpatrickshell. That can be set up e.g. by starting a Visual Studio Tools Command 12076d0caaeSpatrickPrompt (for getting the environment variables pointing to the headers and 12176d0caaeSpatrickimport libraries), and making sure that clang-cl is available in the 12276d0caaeSpatrickpath. From there, launch an MSYS2 shell via e.g. 12376d0caaeSpatrick``C:\msys64\msys2_shell.cmd -full-path -mingw64`` (preserving the earlier 12476d0caaeSpatrickenvironment, allowing the MSVC headers/libraries and clang-cl to be found). 12576d0caaeSpatrick 12676d0caaeSpatrickIn either case, then run: 12746035553Spatrick 12846035553Spatrick.. code-block:: batch 12946035553Spatrick 130*4bdff4beSrobert > cmake -G Ninja -S runtimes -B build ^ 13146035553Spatrick -DCMAKE_C_COMPILER=clang-cl ^ 13246035553Spatrick -DCMAKE_CXX_COMPILER=clang-cl ^ 133*4bdff4beSrobert -DLLVM_ENABLE_RUNTIMES=libcxx 13476d0caaeSpatrick > ninja -C build cxx 13576d0caaeSpatrick > ninja -C build check-cxx 13646035553Spatrick 13776d0caaeSpatrickIf you are running in an MSYS2 shell and you have installed the 13876d0caaeSpatrickMSYS2-provided clang package (which defaults to a non-MSVC target), you 139*4bdff4beSrobertshould add e.g. ``-DCMAKE_CXX_COMPILER_TARGET=x86_64-windows-msvc`` (replacing 14076d0caaeSpatrick``x86_64`` with the architecture you're targeting) to the ``cmake`` command 14176d0caaeSpatrickline above. This will instruct ``check-cxx`` to use the right target triple 14276d0caaeSpatrickwhen invoking ``clang++``. 14376d0caaeSpatrick 14476d0caaeSpatrickAlso note that if not building in Release mode, a failed assert in the tests 14576d0caaeSpatrickpops up a blocking dialog box, making it hard to run a larger number of tests. 14676d0caaeSpatrick 14776d0caaeSpatrickCMake + ninja (MinGW) 14876d0caaeSpatrick--------------------- 14976d0caaeSpatrick 15076d0caaeSpatricklibcxx can also be built in MinGW environments, e.g. with the MinGW 15176d0caaeSpatrickcompilers in MSYS2. This requires clang to be available (installed with 15276d0caaeSpatricke.g. the ``mingw-w64-x86_64-clang`` package), together with CMake and ninja. 15376d0caaeSpatrick 15476d0caaeSpatrick.. code-block:: bash 15576d0caaeSpatrick 156*4bdff4beSrobert > cmake -G Ninja -S runtimes -B build \ 15776d0caaeSpatrick -DCMAKE_C_COMPILER=clang \ 15876d0caaeSpatrick -DCMAKE_CXX_COMPILER=clang++ \ 159*4bdff4beSrobert -DLLVM_ENABLE_RUNTIMES=libcxx \ 160*4bdff4beSrobert -DLIBCXX_CXX_ABI=libstdc++ 16176d0caaeSpatrick > ninja -C build cxx 16276d0caaeSpatrick > cp /mingw64/bin/{libstdc++-6,libgcc_s_seh-1,libwinpthread-1}.dll lib 16376d0caaeSpatrick > ninja -C build check-cxx 16476d0caaeSpatrick 16576d0caaeSpatrickAs this build configuration ends up depending on a couple other DLLs that 16676d0caaeSpatrickaren't available in path while running tests, copy them into the same 16776d0caaeSpatrickdirectory as the tested libc++ DLL. 16876d0caaeSpatrick 16976d0caaeSpatrick(Building a libc++ that depends on libstdc++ isn't necessarily a config one 17076d0caaeSpatrickwould want to deploy, but it simplifies the config for testing purposes.) 17146035553Spatrick 17246035553Spatrick.. _`libc++abi`: http://libcxxabi.llvm.org/ 17346035553Spatrick 17446035553Spatrick 17546035553Spatrick.. _CMake Options: 17646035553Spatrick 17746035553SpatrickCMake Options 17846035553Spatrick============= 17946035553Spatrick 18046035553SpatrickHere are some of the CMake variables that are used often, along with a 18146035553Spatrickbrief explanation and LLVM-specific notes. For full documentation, check the 18246035553SpatrickCMake docs or execute ``cmake --help-variable VARIABLE_NAME``. 18346035553Spatrick 18446035553Spatrick**CMAKE_BUILD_TYPE**:STRING 18546035553Spatrick Sets the build type for ``make`` based generators. Possible values are 18646035553Spatrick Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio 18746035553Spatrick the user sets the build type with the IDE settings. 18846035553Spatrick 18946035553Spatrick**CMAKE_INSTALL_PREFIX**:PATH 19046035553Spatrick Path where LLVM will be installed if "make install" is invoked or the 19146035553Spatrick "INSTALL" target is built. 19246035553Spatrick 19346035553Spatrick**CMAKE_CXX_COMPILER**:STRING 19446035553Spatrick The C++ compiler to use when building and testing libc++. 19546035553Spatrick 19646035553Spatrick 19746035553Spatrick.. _libcxx-specific options: 19846035553Spatrick 19946035553Spatricklibc++ specific options 20046035553Spatrick----------------------- 20146035553Spatrick 20246035553Spatrick.. option:: LIBCXX_INSTALL_LIBRARY:BOOL 20346035553Spatrick 20446035553Spatrick **Default**: ``ON`` 20546035553Spatrick 20646035553Spatrick Toggle the installation of the library portion of libc++. 20746035553Spatrick 20846035553Spatrick.. option:: LIBCXX_INSTALL_HEADERS:BOOL 20946035553Spatrick 21046035553Spatrick **Default**: ``ON`` 21146035553Spatrick 21246035553Spatrick Toggle the installation of the libc++ headers. 21346035553Spatrick 21446035553Spatrick.. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL 21546035553Spatrick 216037e7968Spatrick **Default**: ``OFF`` 21746035553Spatrick 218*4bdff4beSrobert Build libc++ with assertions enabled in the compiled library, and enable assertions 219*4bdff4beSrobert by default when building user code as well. Assertions can be turned off by users 220*4bdff4beSrobert by defining ``_LIBCPP_ENABLE_ASSERTIONS=0``. For details, see 221*4bdff4beSrobert :ref:`the documentation <assertions-mode>`. 22246035553Spatrick 22346035553Spatrick.. option:: LIBCXX_ENABLE_SHARED:BOOL 22446035553Spatrick 22546035553Spatrick **Default**: ``ON`` 22646035553Spatrick 22746035553Spatrick Build libc++ as a shared library. Either `LIBCXX_ENABLE_SHARED` or 22846035553Spatrick `LIBCXX_ENABLE_STATIC` has to be enabled. 22946035553Spatrick 23046035553Spatrick.. option:: LIBCXX_ENABLE_STATIC:BOOL 23146035553Spatrick 23246035553Spatrick **Default**: ``ON`` 23346035553Spatrick 23446035553Spatrick Build libc++ as a static library. Either `LIBCXX_ENABLE_SHARED` or 23546035553Spatrick `LIBCXX_ENABLE_STATIC` has to be enabled. 23646035553Spatrick 23746035553Spatrick.. option:: LIBCXX_LIBDIR_SUFFIX:STRING 23846035553Spatrick 23946035553Spatrick Extra suffix to append to the directory where libraries are to be installed. 24046035553Spatrick This option overrides `LLVM_LIBDIR_SUFFIX`. 24146035553Spatrick 24246035553Spatrick.. option:: LIBCXX_HERMETIC_STATIC_LIBRARY:BOOL 24346035553Spatrick 24446035553Spatrick **Default**: ``OFF`` 24546035553Spatrick 24646035553Spatrick Do not export any symbols from the static libc++ library. 24746035553Spatrick This is useful when the static libc++ library is being linked into shared 24846035553Spatrick libraries that may be used in with other shared libraries that use different 24946035553Spatrick C++ library. We want to avoid exporting any libc++ symbols in that case. 25046035553Spatrick 25146035553Spatrick.. option:: LIBCXX_ENABLE_FILESYSTEM:BOOL 25246035553Spatrick 25376d0caaeSpatrick **Default**: ``ON`` except on Windows when using MSVC. 25446035553Spatrick 25546035553Spatrick This option can be used to enable or disable the filesystem components on 25676d0caaeSpatrick platforms that may not support them. For example on Windows when using MSVC. 25776d0caaeSpatrick 258*4bdff4beSrobert.. option:: LIBCXX_ENABLE_WIDE_CHARACTERS:BOOL 25976d0caaeSpatrick 26076d0caaeSpatrick **Default**: ``ON`` 26176d0caaeSpatrick 262*4bdff4beSrobert This option can be used to disable support for ``wchar_t`` in the library. It also 263*4bdff4beSrobert allows the library to work on top of a C Standard Library that does not provide 264*4bdff4beSrobert support for ``wchar_t``. This is especially useful in embedded settings where 265*4bdff4beSrobert C Standard Libraries don't always provide all the usual bells and whistles. 26676d0caaeSpatrick 26776d0caaeSpatrick.. option:: LIBCXX_INSTALL_LIBRARY_DIR:PATH 26876d0caaeSpatrick 26976d0caaeSpatrick **Default**: ``lib${LIBCXX_LIBDIR_SUFFIX}`` 27076d0caaeSpatrick 27176d0caaeSpatrick Path where built libc++ libraries should be installed. If a relative path, 27276d0caaeSpatrick relative to ``CMAKE_INSTALL_PREFIX``. 27376d0caaeSpatrick 27476d0caaeSpatrick.. option:: LIBCXX_INSTALL_INCLUDE_DIR:PATH 27576d0caaeSpatrick 27676d0caaeSpatrick **Default**: ``include/c++/v1`` 27776d0caaeSpatrick 27876d0caaeSpatrick Path where target-agnostic libc++ headers should be installed. If a relative 27976d0caaeSpatrick path, relative to ``CMAKE_INSTALL_PREFIX``. 28076d0caaeSpatrick 28176d0caaeSpatrick.. option:: LIBCXX_INSTALL_INCLUDE_TARGET_DIR:PATH 28276d0caaeSpatrick 28376d0caaeSpatrick **Default**: ``include/c++/v1`` or 28476d0caaeSpatrick ``include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1`` 28576d0caaeSpatrick 28676d0caaeSpatrick Path where target-specific libc++ headers should be installed. If a relative 28776d0caaeSpatrick path, relative to ``CMAKE_INSTALL_PREFIX``. 28846035553Spatrick 289*4bdff4beSrobert.. option:: LIBCXX_SHARED_OUTPUT_NAME:STRING 29046035553Spatrick 291*4bdff4beSrobert **Default**: ``c++`` 29246035553Spatrick 293*4bdff4beSrobert Output name for the shared libc++ runtime library. 29446035553Spatrick 295*4bdff4beSrobert.. option:: LIBCXX_ADDITIONAL_COMPILE_FLAGS:STRING 29646035553Spatrick 297*4bdff4beSrobert **Default**: ``""`` 29846035553Spatrick 299*4bdff4beSrobert Additional Compile only flags which can be provided in cache. 30046035553Spatrick 301*4bdff4beSrobert.. option:: LIBCXX_ADDITIONAL_LIBRARIES:STRING 30246035553Spatrick 303*4bdff4beSrobert **Default**: ``""`` 304*4bdff4beSrobert 305*4bdff4beSrobert Additional libraries libc++ is linked to which can be provided in cache. 30646035553Spatrick 30746035553Spatrick 30846035553Spatrick.. _ABI Library Specific Options: 30946035553Spatrick 31046035553SpatrickABI Library Specific Options 31146035553Spatrick---------------------------- 31246035553Spatrick 31346035553Spatrick.. option:: LIBCXX_CXX_ABI:STRING 31446035553Spatrick 315*4bdff4beSrobert **Values**: ``none``, ``libcxxabi``, ``system-libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``, ``vcruntime``. 31646035553Spatrick 31746035553Spatrick Select the ABI library to build libc++ against. 31846035553Spatrick 31946035553Spatrick.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS 32046035553Spatrick 32146035553Spatrick Provide additional search paths for the ABI library headers. 32246035553Spatrick 32346035553Spatrick.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH 32446035553Spatrick 325*4bdff4beSrobert Provide the path to the ABI library that libc++ should link against. This is only 326*4bdff4beSrobert useful when linking against an out-of-tree ABI library. 32746035553Spatrick 32846035553Spatrick.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL 32946035553Spatrick 33046035553Spatrick **Default**: ``OFF`` 33146035553Spatrick 33246035553Spatrick If this option is enabled, libc++ will try and link the selected ABI library 33346035553Spatrick statically. 33446035553Spatrick 33546035553Spatrick.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL 33646035553Spatrick 33746035553Spatrick **Default**: ``ON`` by default on UNIX platforms other than Apple unless 33846035553Spatrick 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``. 33946035553Spatrick 34046035553Spatrick This option generate and installs a linker script as ``libc++.so`` which 34146035553Spatrick links the correct ABI library. 34246035553Spatrick 34346035553Spatrick.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL 34446035553Spatrick 34546035553Spatrick **Default**: ``OFF`` 34646035553Spatrick 34746035553Spatrick Build and use the LLVM unwinder. Note: This option can only be used when 34846035553Spatrick libc++abi is the C++ ABI library used. 34946035553Spatrick 350*4bdff4beSrobert.. option:: LIBCXXABI_ADDITIONAL_COMPILE_FLAGS:STRING 351*4bdff4beSrobert 352*4bdff4beSrobert **Default**: ``""`` 353*4bdff4beSrobert 354*4bdff4beSrobert Additional Compile only flags which can be provided in cache. 355*4bdff4beSrobert 356*4bdff4beSrobert.. option:: LIBCXXABI_ADDITIONAL_LIBRARIES:STRING 357*4bdff4beSrobert 358*4bdff4beSrobert **Default**: ``""`` 359*4bdff4beSrobert 360*4bdff4beSrobert Additional libraries libc++abi is linked to which can be provided in cache. 361*4bdff4beSrobert 36246035553Spatrick 36346035553Spatricklibc++ Feature Options 36446035553Spatrick---------------------- 36546035553Spatrick 36646035553Spatrick.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL 36746035553Spatrick 36846035553Spatrick **Default**: ``ON`` 36946035553Spatrick 37046035553Spatrick Build libc++ with exception support. 37146035553Spatrick 37246035553Spatrick.. option:: LIBCXX_ENABLE_RTTI:BOOL 37346035553Spatrick 37446035553Spatrick **Default**: ``ON`` 37546035553Spatrick 37646035553Spatrick Build libc++ with run time type information. 37746035553Spatrick 37846035553Spatrick.. option:: LIBCXX_INCLUDE_TESTS:BOOL 37946035553Spatrick 38076d0caaeSpatrick **Default**: ``ON`` (or value of ``LLVM_INCLUDE_TESTS``) 38146035553Spatrick 38246035553Spatrick Build the libc++ tests. 38346035553Spatrick 38446035553Spatrick.. option:: LIBCXX_INCLUDE_BENCHMARKS:BOOL 38546035553Spatrick 38646035553Spatrick **Default**: ``ON`` 38746035553Spatrick 38846035553Spatrick Build the libc++ benchmark tests and the Google Benchmark library needed 38946035553Spatrick to support them. 39046035553Spatrick 39146035553Spatrick.. option:: LIBCXX_BENCHMARK_TEST_ARGS:STRING 39246035553Spatrick 39346035553Spatrick **Default**: ``--benchmark_min_time=0.01`` 39446035553Spatrick 39546035553Spatrick A semicolon list of arguments to pass when running the libc++ benchmarks using the 39646035553Spatrick ``check-cxx-benchmarks`` rule. By default we run the benchmarks for a very short amount of time, 39746035553Spatrick since the primary use of ``check-cxx-benchmarks`` is to get test and sanitizer coverage, not to 39846035553Spatrick get accurate measurements. 39946035553Spatrick 40046035553Spatrick.. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING 40146035553Spatrick 40246035553Spatrick **Default**:: ``""`` 40346035553Spatrick 40446035553Spatrick **Values**:: ``libc++``, ``libstdc++`` 40546035553Spatrick 40646035553Spatrick Build the libc++ benchmark tests and Google Benchmark library against the 40746035553Spatrick specified standard library on the platform. On Linux this can be used to 40846035553Spatrick compare libc++ to libstdc++ by building the benchmark tests against both 40946035553Spatrick standard libraries. 41046035553Spatrick 41146035553Spatrick.. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING 41246035553Spatrick 41346035553Spatrick Use the specified GCC toolchain and standard library when building the native 41446035553Spatrick stdlib benchmark tests. 41546035553Spatrick 41646035553Spatrick 41746035553Spatricklibc++ ABI Feature Options 41846035553Spatrick-------------------------- 41946035553Spatrick 42046035553SpatrickThe following options allow building libc++ for a different ABI version. 42146035553Spatrick 42246035553Spatrick.. option:: LIBCXX_ABI_VERSION:STRING 42346035553Spatrick 42446035553Spatrick **Default**: ``1`` 42546035553Spatrick 42646035553Spatrick Defines the target ABI version of libc++. 42746035553Spatrick 42846035553Spatrick.. option:: LIBCXX_ABI_UNSTABLE:BOOL 42946035553Spatrick 43046035553Spatrick **Default**: ``OFF`` 43146035553Spatrick 43246035553Spatrick Build the "unstable" ABI version of libc++. Includes all ABI changing features 43346035553Spatrick on top of the current stable version. 43446035553Spatrick 43546035553Spatrick.. option:: LIBCXX_ABI_NAMESPACE:STRING 43646035553Spatrick 43746035553Spatrick **Default**: ``__n`` where ``n`` is the current ABI version. 43846035553Spatrick 43946035553Spatrick This option defines the name of the inline ABI versioning namespace. It can be used for building 44046035553Spatrick custom versions of libc++ with unique symbol names in order to prevent conflicts or ODR issues 44146035553Spatrick with other libc++ versions. 44246035553Spatrick 44346035553Spatrick .. warning:: 444*4bdff4beSrobert When providing a custom namespace, it's the user's responsibility to ensure the name won't cause 44546035553Spatrick conflicts with other names defined by libc++, both now and in the future. In particular, inline 446*4bdff4beSrobert namespaces of the form ``__[0-9]+`` could cause conflicts with future versions of the library, 447*4bdff4beSrobert and so should be avoided. 44846035553Spatrick 44946035553Spatrick.. option:: LIBCXX_ABI_DEFINES:STRING 45046035553Spatrick 45146035553Spatrick **Default**: ``""`` 45246035553Spatrick 45346035553Spatrick A semicolon-separated list of ABI macros to persist in the site config header. 45446035553Spatrick See ``include/__config`` for the list of ABI macros. 45546035553Spatrick 45646035553Spatrick 45746035553Spatrick.. _LLVM-specific variables: 45846035553Spatrick 45946035553SpatrickLLVM-specific options 46046035553Spatrick--------------------- 46146035553Spatrick 46246035553Spatrick.. option:: LLVM_LIBDIR_SUFFIX:STRING 46346035553Spatrick 46446035553Spatrick Extra suffix to append to the directory where libraries are to be 46546035553Spatrick installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` 46646035553Spatrick to install libraries to ``/usr/lib64``. 46746035553Spatrick 46846035553Spatrick.. option:: LLVM_BUILD_32_BITS:BOOL 46946035553Spatrick 47046035553Spatrick Build 32-bits executables and libraries on 64-bits systems. This option is 47146035553Spatrick available only on some 64-bits Unix systems. Defaults to OFF. 47246035553Spatrick 47346035553Spatrick.. option:: LLVM_LIT_ARGS:STRING 47446035553Spatrick 47546035553Spatrick Arguments given to lit. ``make check`` and ``make clang-test`` are affected. 47646035553Spatrick By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on 47746035553Spatrick others. 47846035553Spatrick 47946035553Spatrick 48046035553SpatrickUsing Alternate ABI libraries 48146035553Spatrick============================= 48246035553Spatrick 48376d0caaeSpatrickIn order to implement various features like exceptions, RTTI, ``dynamic_cast`` and 48476d0caaeSpatrickmore, libc++ requires what we refer to as an ABI library. Typically, that library 48576d0caaeSpatrickimplements the `Itanium C++ ABI <https://itanium-cxx-abi.github.io/cxx-abi/abi.html>`_. 48646035553Spatrick 48776d0caaeSpatrickBy default, libc++ uses libc++abi as an ABI library. However, it is possible to use 48876d0caaeSpatrickother ABI libraries too. 48946035553Spatrick 49046035553SpatrickUsing libsupc++ on Linux 49146035553Spatrick------------------------ 49246035553Spatrick 49346035553SpatrickYou will need libstdc++ in order to provide libsupc++. 49446035553Spatrick 49546035553SpatrickFigure out where the libsupc++ headers are on your system. On Ubuntu this 49646035553Spatrickis ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>`` 49746035553Spatrick 49846035553SpatrickYou can also figure this out by running 49946035553Spatrick 50046035553Spatrick.. code-block:: bash 50146035553Spatrick 50246035553Spatrick $ echo | g++ -Wp,-v -x c++ - -fsyntax-only 50346035553Spatrick ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" 50446035553Spatrick ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include" 50546035553Spatrick #include "..." search starts here: 50646035553Spatrick #include <...> search starts here: 50746035553Spatrick /usr/include/c++/4.7 50846035553Spatrick /usr/include/c++/4.7/x86_64-linux-gnu 50946035553Spatrick /usr/include/c++/4.7/backward 51046035553Spatrick /usr/lib/gcc/x86_64-linux-gnu/4.7/include 51146035553Spatrick /usr/local/include 51246035553Spatrick /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed 51346035553Spatrick /usr/include/x86_64-linux-gnu 51446035553Spatrick /usr/include 51546035553Spatrick End of search list. 51646035553Spatrick 51746035553SpatrickNote that the first two entries happen to be what we are looking for. This 51876d0caaeSpatrickmay not be correct on all platforms. 51946035553Spatrick 52046035553SpatrickWe can now run CMake: 52146035553Spatrick 52246035553Spatrick.. code-block:: bash 52346035553Spatrick 524*4bdff4beSrobert $ cmake -G Ninja -S runtimes -B build \ 525*4bdff4beSrobert -DLLVM_ENABLE_RUNTIMES="libcxx" \ 52646035553Spatrick -DLIBCXX_CXX_ABI=libstdc++ \ 52776d0caaeSpatrick -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" 52876d0caaeSpatrick $ ninja -C build install-cxx 52946035553Spatrick 53046035553Spatrick 53146035553SpatrickYou can also substitute ``-DLIBCXX_CXX_ABI=libsupc++`` 53246035553Spatrickabove, which will cause the library to be linked to libsupc++ instead 53346035553Spatrickof libstdc++, but this is only recommended if you know that you will 53446035553Spatricknever need to link against libstdc++ in the same executable as libc++. 53546035553SpatrickGCC ships libsupc++ separately but only as a static library. If a 53646035553Spatrickprogram also needs to link against libstdc++, it will provide its 53746035553Spatrickown copy of libsupc++ and this can lead to subtle problems. 53846035553Spatrick 53946035553SpatrickUsing libcxxrt on Linux 54046035553Spatrick------------------------ 54146035553Spatrick 54246035553SpatrickYou will need to keep the source tree of `libcxxrt`_ available 54346035553Spatrickon your build machine and your copy of the libcxxrt shared library must 54446035553Spatrickbe placed where your linker will find it. 54546035553Spatrick 54646035553SpatrickWe can now run CMake like: 54746035553Spatrick 54846035553Spatrick.. code-block:: bash 54946035553Spatrick 550*4bdff4beSrobert $ cmake -G Ninja -S runtimes -B build \ 551*4bdff4beSrobert -DLLVM_ENABLE_RUNTIMES="libcxx" \ 55246035553Spatrick -DLIBCXX_CXX_ABI=libcxxrt \ 55376d0caaeSpatrick -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxrt-sources/src 55476d0caaeSpatrick $ ninja -C build install-cxx 55546035553Spatrick 55646035553SpatrickUnfortunately you can't simply run clang with "-stdlib=libc++" at this point, as 55746035553Spatrickclang is set up to link for libc++ linked to libsupc++. To get around this 55846035553Spatrickyou'll have to set up your linker yourself (or patch clang). For example, 55946035553Spatrick 56046035553Spatrick.. code-block:: bash 56146035553Spatrick 56246035553Spatrick $ clang++ -stdlib=libc++ helloworld.cpp \ 56346035553Spatrick -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc 56446035553Spatrick 56546035553SpatrickAlternately, you could just add libcxxrt to your libraries list, which in most 56646035553Spatricksituations will give the same result: 56746035553Spatrick 56846035553Spatrick.. code-block:: bash 56946035553Spatrick 57046035553Spatrick $ clang++ -stdlib=libc++ helloworld.cpp -lcxxrt 57146035553Spatrick 57276d0caaeSpatrick.. _`libcxxrt`: https://github.com/libcxxrt/libcxxrt 573