blob: a0128b84eeb4354b050b153719e9e050804c1a95 [file] [log] [blame]
Eric Fiseliera0733922016-06-02 02:16:28 +00001.. _BuildingLibcxx:
Eric Fiselierd720d1f2015-08-22 19:40:49 +00002
3===============
4Building libc++
5===============
6
7.. contents::
8 :local:
9
Eric Fiselierfa43a5c2016-05-03 22:32:08 +000010.. _build instructions:
11
Louis Dionne4b1b70d2021-07-06 10:39:01 -040012The instructions on this page are aimed at vendors who ship libc++ as part of an
13operating system distribution, a toolchain or similar shipping vehicules. If you
14are a user merely trying to use libc++ in your program, you most likely want to
15refer to your vendor's documentation, or to the general documentation for using
16libc++ :ref:`here <using-libcxx>`.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000017
Dan Albert08302aa2019-11-07 12:40:05 -080018.. warning::
Louis Dionne4b1b70d2021-07-06 10:39:01 -040019 If your operating system already provides libc++, it is important to be careful
20 not to replace it. Replacing your system's libc++ installation could render it
21 non-functional. Use the CMake option ``CMAKE_INSTALL_PREFIX`` to select a safe
22 place to install libc++.
23
24
25The default build
26=================
27
28By default, libc++ and libc++abi are built as sub-projects of the LLVM project.
29This can be achieved with the usual CMake invocation:
Eric Fiselierd720d1f2015-08-22 19:40:49 +000030
Dan Albert08302aa2019-11-07 12:40:05 -080031.. code-block:: bash
Eric Fiselierd720d1f2015-08-22 19:40:49 +000032
Dan Albert08302aa2019-11-07 12:40:05 -080033 $ git clone https://github.com/llvm/llvm-project.git
34 $ cd llvm-project
Louis Dionne4b1b70d2021-07-06 10:39:01 -040035 $ mkdir build
36 $ cmake -G Ninja -S llvm -B build -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" # Configure
37 $ ninja -C build cxx cxxabi # Build
38 $ ninja -C build check-cxx check-cxxabi # Test
39 $ ninja -C build install-cxx install-cxxabi # Install
Eric Fiselierd720d1f2015-08-22 19:40:49 +000040
Louis Dionne4b1b70d2021-07-06 10:39:01 -040041.. note::
42 See :ref:`CMake Options` below for more configuration options.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000043
Louis Dionne4b1b70d2021-07-06 10:39:01 -040044After building the ``install-cxx`` and ``install-cxxabi`` targets, shared libraries
45for libc++ and libc++abi should now be present in ``<CMAKE_INSTALL_PREFIX>/lib``, and
46headers in ``<CMAKE_INSTALL_PREFIX>/include/c++/v1``. See :ref:`using an alternate
47libc++ installation <alternate libcxx>` for information on how to use this libc++ over
48the default one.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000049
Louis Dionne4b1b70d2021-07-06 10:39:01 -040050In the default configuration, libc++ and libc++abi will be built using the compiler available
51by default on your system. It is also possible to bootstrap Clang and build libc++ with it.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000052
Louis Dionne4b1b70d2021-07-06 10:39:01 -040053
54Bootstrapping build
55===================
56
57It is also possible to build Clang and then build libc++ and libc++abi using that
58just-built compiler. This is the correct way to build libc++ when putting together
59a toolchain, or when the system compiler is not adequate to build libc++ (too old,
60unsupported, etc.). This type of build is also commonly called a "Runtimes build":
Eric Fiselierd720d1f2015-08-22 19:40:49 +000061
62.. code-block:: bash
63
Louis Dionne4b1b70d2021-07-06 10:39:01 -040064 $ mkdir build
65 $ cmake -G Ninja -S llvm -B build -DLLVM_ENABLE_PROJECTS="clang" \ # Configure
66 -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
67 -DLLVM_RUNTIME_TARGETS="<target-triple>"
68 $ ninja -C build runtimes # Build
69 $ ninja -C build check-runtimes # Test
70 $ ninja -C build install-runtimes # Install
Eric Fiselierd720d1f2015-08-22 19:40:49 +000071
72
Martin Storsjöf9535f72021-02-22 01:20:28 +020073Support for Windows
Louis Dionne4b1b70d2021-07-06 10:39:01 -040074===================
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000075
Martin Storsjöf9535f72021-02-22 01:20:28 +020076libcxx supports being built with clang-cl, but not with MSVC's cl.exe, as
Martin Storsjöbb9586b2021-03-17 11:40:17 +020077cl doesn't support the ``#include_next`` extension. Furthermore, VS 2017 or
Martin Storsjöf9535f72021-02-22 01:20:28 +020078newer (19.14) is required.
79
80libcxx also supports being built with clang targeting MinGW environments.
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000081
82CMake + Visual Studio
Louis Dionne4b1b70d2021-07-06 10:39:01 -040083---------------------
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000084
85Building with Visual Studio currently does not permit running tests. However,
86it is the simplest way to build.
87
88.. code-block:: batch
89
Louis Dionne4b1b70d2021-07-06 10:39:01 -040090 > cmake -G "Visual Studio 16 2019" -S libcxx -B build ^
91 -T "ClangCL" ^
92 -DLIBCXX_ENABLE_SHARED=YES ^
93 -DLIBCXX_ENABLE_STATIC=NO ^
94 -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO
95 > cmake --build build
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000096
Martin Storsjöf9535f72021-02-22 01:20:28 +020097CMake + ninja (MSVC)
Louis Dionne4b1b70d2021-07-06 10:39:01 -040098--------------------
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000099
100Building with ninja is required for development to enable tests.
Martin Storsjö9728c102021-05-03 22:14:00 +0300101A couple of tests require Bash to be available, and a couple dozens
102of tests require other posix tools (cp, grep and similar - LLVM's tests
103require the same). Without those tools the vast majority of tests
104can still be ran successfully.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200105
106If Git for Windows is available, that can be used to provide the bash
107shell by adding the right bin directory to the path, e.g.
Martin Storsjöbb9586b2021-03-17 11:40:17 +0200108``set PATH=%PATH%;C:\Program Files\Git\usr\bin``.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200109
110Alternatively, one can also choose to run the whole build in a MSYS2
111shell. That can be set up e.g. by starting a Visual Studio Tools Command
112Prompt (for getting the environment variables pointing to the headers and
113import libraries), and making sure that clang-cl is available in the
114path. From there, launch an MSYS2 shell via e.g.
Martin Storsjöbb9586b2021-03-17 11:40:17 +0200115``C:\msys64\msys2_shell.cmd -full-path -mingw64`` (preserving the earlier
Martin Storsjöf9535f72021-02-22 01:20:28 +0200116environment, allowing the MSVC headers/libraries and clang-cl to be found).
117
118In either case, then run:
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000119
120.. code-block:: batch
121
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400122 > cmake -G Ninja -S libcxx -B build ^
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000123 -DCMAKE_C_COMPILER=clang-cl ^
Martin Storsjöf9535f72021-02-22 01:20:28 +0200124 -DCMAKE_CXX_COMPILER=clang-cl ^
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400125 -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO
126 > ninja -C build cxx
127 > ninja -C build check-cxx
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000128
Martin Storsjöf9535f72021-02-22 01:20:28 +0200129If you are running in an MSYS2 shell and you have installed the
130MSYS2-provided clang package (which defaults to a non-MSVC target), you
Martin Storsjöbb9586b2021-03-17 11:40:17 +0200131should add e.g. ``-DLIBCXX_TARGET_TRIPLE=x86_64-windows-msvc`` (replacing
132``x86_64`` with the architecture you're targeting) to the ``cmake`` command
133line above. This will instruct ``check-cxx`` to use the right target triple
134when invoking ``clang++``.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200135
136Also note that if not building in Release mode, a failed assert in the tests
137pops up a blocking dialog box, making it hard to run a larger number of tests.
138
139CMake + ninja (MinGW)
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400140---------------------
Martin Storsjöf9535f72021-02-22 01:20:28 +0200141
142libcxx can also be built in MinGW environments, e.g. with the MinGW
143compilers in MSYS2. This requires clang to be available (installed with
Martin Storsjöbb9586b2021-03-17 11:40:17 +0200144e.g. the ``mingw-w64-x86_64-clang`` package), together with CMake and ninja.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200145
146.. code-block:: bash
147
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400148 > cmake -G Ninja -S libcxx -B build \
Martin Storsjöf9535f72021-02-22 01:20:28 +0200149 -DCMAKE_C_COMPILER=clang \
150 -DCMAKE_CXX_COMPILER=clang++ \
151 -DLIBCXX_HAS_WIN32_THREAD_API=ON \
152 -DLIBCXX_CXX_ABI=libstdc++ \
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400153 -DLIBCXX_TARGET_INFO="libcxx.test.target_info.MingwLocalTI"
154 > ninja -C build cxx
Martin Storsjöf9535f72021-02-22 01:20:28 +0200155 > cp /mingw64/bin/{libstdc++-6,libgcc_s_seh-1,libwinpthread-1}.dll lib
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400156 > ninja -C build check-cxx
Martin Storsjöf9535f72021-02-22 01:20:28 +0200157
158As this build configuration ends up depending on a couple other DLLs that
159aren't available in path while running tests, copy them into the same
160directory as the tested libc++ DLL.
161
162(Building a libc++ that depends on libstdc++ isn't necessarily a config one
163would want to deploy, but it simplifies the config for testing purposes.)
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000164
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000165.. _`libc++abi`: http://libcxxabi.llvm.org/
166
167
168.. _CMake Options:
169
170CMake Options
171=============
172
173Here are some of the CMake variables that are used often, along with a
174brief explanation and LLVM-specific notes. For full documentation, check the
175CMake docs or execute ``cmake --help-variable VARIABLE_NAME``.
176
177**CMAKE_BUILD_TYPE**:STRING
178 Sets the build type for ``make`` based generators. Possible values are
179 Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio
180 the user sets the build type with the IDE settings.
181
182**CMAKE_INSTALL_PREFIX**:PATH
183 Path where LLVM will be installed if "make install" is invoked or the
184 "INSTALL" target is built.
185
186**CMAKE_CXX_COMPILER**:STRING
187 The C++ compiler to use when building and testing libc++.
188
189
190.. _libcxx-specific options:
191
192libc++ specific options
193-----------------------
194
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000195.. option:: LIBCXX_INSTALL_LIBRARY:BOOL
196
197 **Default**: ``ON``
198
199 Toggle the installation of the library portion of libc++.
200
201.. option:: LIBCXX_INSTALL_HEADERS:BOOL
202
203 **Default**: ``ON``
204
205 Toggle the installation of the libc++ headers.
206
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000207.. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL
208
Raul Tambree3f9fa52020-03-30 12:44:15 -0400209 **Default**: ``OFF``
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000210
211 Build libc++ with assertions enabled.
212
213.. option:: LIBCXX_BUILD_32_BITS:BOOL
214
215 **Default**: ``OFF``
216
Eric Fiselier887b86b2016-09-16 03:47:53 +0000217 Build libc++ as a 32 bit library. Also see `LLVM_BUILD_32_BITS`.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000218
219.. option:: LIBCXX_ENABLE_SHARED:BOOL
220
221 **Default**: ``ON``
222
Eric Fiselier887b86b2016-09-16 03:47:53 +0000223 Build libc++ as a shared library. Either `LIBCXX_ENABLE_SHARED` or
224 `LIBCXX_ENABLE_STATIC` has to be enabled.
Petr Hosek13620052016-08-08 22:57:25 +0000225
226.. option:: LIBCXX_ENABLE_STATIC:BOOL
227
228 **Default**: ``ON``
229
Eric Fiselier887b86b2016-09-16 03:47:53 +0000230 Build libc++ as a static library. Either `LIBCXX_ENABLE_SHARED` or
231 `LIBCXX_ENABLE_STATIC` has to be enabled.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000232
233.. option:: LIBCXX_LIBDIR_SUFFIX:STRING
234
235 Extra suffix to append to the directory where libraries are to be installed.
Eric Fiselier887b86b2016-09-16 03:47:53 +0000236 This option overrides `LLVM_LIBDIR_SUFFIX`.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000237
Petr Hosekb42e3492019-01-06 06:14:31 +0000238.. option:: LIBCXX_HERMETIC_STATIC_LIBRARY:BOOL
239
240 **Default**: ``OFF``
241
Jonathan Metzmance2328d2019-04-10 23:44:27 +0000242 Do not export any symbols from the static libc++ library.
Petr Hosekb42e3492019-01-06 06:14:31 +0000243 This is useful when the static libc++ library is being linked into shared
244 libraries that may be used in with other shared libraries that use different
Louis Dionned0889672019-08-23 19:42:09 +0000245 C++ library. We want to avoid exporting any libc++ symbols in that case.
Petr Hosekb42e3492019-01-06 06:14:31 +0000246
Eric Fiselier72e2dd82019-03-21 00:04:31 +0000247.. option:: LIBCXX_ENABLE_FILESYSTEM:BOOL
248
Mark de Wever42bf3d02021-07-29 07:54:48 +0200249 **Default**: ``ON`` except on Windows when using MSVC.
Eric Fiselier72e2dd82019-03-21 00:04:31 +0000250
251 This option can be used to enable or disable the filesystem components on
Mark de Wever42bf3d02021-07-29 07:54:48 +0200252 platforms that may not support them. For example on Windows when using MSVC.
Eric Fiselier72e2dd82019-03-21 00:04:31 +0000253
Louis Dionne89258142021-08-23 15:32:36 -0400254.. option:: LIBCXX_ENABLE_WIDE_CHARACTERS:BOOL
255
256 **Default**: ``ON``
257
258 This option can be used to disable support for ``wchar_t`` in the library. It also
259 allows the library to work on top of a C Standard Library that does not provide
260 support for ``wchar_t``. This is especially useful in embedded settings where
261 C Standard Libraries don't always provide all the usual bells and whistles.
262
Mark de Wever8a0a1882021-07-25 09:18:53 +0200263.. option:: LIBCXX_ENABLE_INCOMPLETE_FEATURES:BOOL
264
265 **Default**: ``ON``
266
267 Whether to enable support for incomplete library features. Incomplete features
268 are new library features under development. These features don't guarantee
269 ABI stability nor the quality of completed library features. Vendors
270 shipping the library may want to disable this option.
271
John Ericson97c6f272021-04-28 22:36:47 +0000272.. option:: LIBCXX_INSTALL_LIBRARY_DIR:PATH
273
274 **Default**: ``lib${LIBCXX_LIBDIR_SUFFIX}``
275
276 Path where built libc++ libraries should be installed. If a relative path,
277 relative to ``CMAKE_INSTALL_PREFIX``.
278
279.. option:: LIBCXX_INSTALL_INCLUDE_DIR:PATH
280
281 **Default**: ``include/c++/v1``
282
283 Path where target-agnostic libc++ headers should be installed. If a relative
284 path, relative to ``CMAKE_INSTALL_PREFIX``.
285
286.. option:: LIBCXX_INSTALL_INCLUDE_TARGET_DIR:PATH
287
288 **Default**: ``include/c++/v1`` or
289 ``include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1``
290
291 Path where target-specific libc++ headers should be installed. If a relative
292 path, relative to ``CMAKE_INSTALL_PREFIX``.
293
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000294.. _libc++experimental options:
295
296libc++experimental Specific Options
297------------------------------------
298
299.. option:: LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL
300
301 **Default**: ``ON``
302
303 Build and test libc++experimental.a.
304
305.. option:: LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY:BOOL
306
Eric Fiselier121594e2016-09-07 01:15:10 +0000307 **Default**: ``LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY AND LIBCXX_INSTALL_LIBRARY``
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000308
309 Install libc++experimental.a alongside libc++.
310
311
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000312.. _ABI Library Specific Options:
313
314ABI Library Specific Options
315----------------------------
316
317.. option:: LIBCXX_CXX_ABI:STRING
318
319 **Values**: ``none``, ``libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``.
320
321 Select the ABI library to build libc++ against.
322
323.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS
324
325 Provide additional search paths for the ABI library headers.
326
327.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH
328
329 Provide the path to the ABI library that libc++ should link against.
330
331.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL
332
333 **Default**: ``OFF``
334
335 If this option is enabled, libc++ will try and link the selected ABI library
336 statically.
337
Eric Fiselier0b09dd12015-10-15 22:41:51 +0000338.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL
339
340 **Default**: ``ON`` by default on UNIX platforms other than Apple unless
341 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``.
342
343 This option generate and installs a linker script as ``libc++.so`` which
344 links the correct ABI library.
345
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000346.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
347
348 **Default**: ``OFF``
349
350 Build and use the LLVM unwinder. Note: This option can only be used when
351 libc++abi is the C++ ABI library used.
352
353
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000354libc++ Feature Options
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000355----------------------
356
357.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
358
359 **Default**: ``ON``
360
361 Build libc++ with exception support.
362
363.. option:: LIBCXX_ENABLE_RTTI:BOOL
364
365 **Default**: ``ON``
366
367 Build libc++ with run time type information.
368
Saleem Abdulrasool1e06a1d2019-07-04 19:08:16 +0000369.. option:: LIBCXX_INCLUDE_TESTS:BOOL
370
Nico Weberf1038c22021-02-18 11:58:48 -0500371 **Default**: ``ON`` (or value of ``LLVM_INCLUDE_TESTS``)
Saleem Abdulrasool1e06a1d2019-07-04 19:08:16 +0000372
373 Build the libc++ tests.
374
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000375.. option:: LIBCXX_INCLUDE_BENCHMARKS:BOOL
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000376
Eric Fiselier93f212c2016-08-29 19:50:49 +0000377 **Default**: ``ON``
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000378
379 Build the libc++ benchmark tests and the Google Benchmark library needed
380 to support them.
381
Eric Fiselier453bc182018-11-14 20:38:46 +0000382.. option:: LIBCXX_BENCHMARK_TEST_ARGS:STRING
383
384 **Default**: ``--benchmark_min_time=0.01``
385
386 A semicolon list of arguments to pass when running the libc++ benchmarks using the
387 ``check-cxx-benchmarks`` rule. By default we run the benchmarks for a very short amount of time,
388 since the primary use of ``check-cxx-benchmarks`` is to get test and sanitizer coverage, not to
389 get accurate measurements.
390
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000391.. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000392
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000393 **Default**:: ``""``
394
395 **Values**:: ``libc++``, ``libstdc++``
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000396
397 Build the libc++ benchmark tests and Google Benchmark library against the
Louis Dionneecc89552019-10-01 20:34:50 +0000398 specified standard library on the platform. On Linux this can be used to
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000399 compare libc++ to libstdc++ by building the benchmark tests against both
400 standard libraries.
401
402.. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING
403
404 Use the specified GCC toolchain and standard library when building the native
405 stdlib benchmark tests.
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000406
Louis Dionne1821de42018-08-16 12:44:28 +0000407.. option:: LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT:BOOL
408
409 **Default**: ``OFF``
410
411 Pick the default for whether to constrain ABI-unstable symbols to
412 each individual translation unit. This setting controls whether
413 `_LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT` is defined by default --
414 see the documentation of that macro for details.
415
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000416
417libc++ ABI Feature Options
418--------------------------
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000419
420The following options allow building libc++ for a different ABI version.
421
422.. option:: LIBCXX_ABI_VERSION:STRING
423
424 **Default**: ``1``
425
426 Defines the target ABI version of libc++.
427
428.. option:: LIBCXX_ABI_UNSTABLE:BOOL
429
430 **Default**: ``OFF``
431
432 Build the "unstable" ABI version of libc++. Includes all ABI changing features
433 on top of the current stable version.
434
Eric Fiselierb33778a2018-10-30 21:44:53 +0000435.. option:: LIBCXX_ABI_NAMESPACE:STRING
436
437 **Default**: ``__n`` where ``n`` is the current ABI version.
438
439 This option defines the name of the inline ABI versioning namespace. It can be used for building
440 custom versions of libc++ with unique symbol names in order to prevent conflicts or ODR issues
441 with other libc++ versions.
442
443 .. warning::
444 When providing a custom namespace, it's the users responsibility to ensure the name won't cause
Louis Dionne6f2c6fb2018-11-16 14:57:47 +0000445 conflicts with other names defined by libc++, both now and in the future. In particular, inline
446 namespaces of the form ``__[0-9]+`` are strictly reserved by libc++ and may not be used by users.
447 Doing otherwise could cause conflicts and hinder libc++ ABI evolution.
Eric Fiselierb33778a2018-10-30 21:44:53 +0000448
Shoaib Meenai4ca4b7c2017-10-04 23:17:12 +0000449.. option:: LIBCXX_ABI_DEFINES:STRING
450
451 **Default**: ``""``
452
453 A semicolon-separated list of ABI macros to persist in the site config header.
454 See ``include/__config`` for the list of ABI macros.
455
Eric Fiselierf3566292019-05-29 02:21:37 +0000456
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000457.. _LLVM-specific variables:
458
459LLVM-specific options
460---------------------
461
462.. option:: LLVM_LIBDIR_SUFFIX:STRING
463
464 Extra suffix to append to the directory where libraries are to be
465 installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
466 to install libraries to ``/usr/lib64``.
467
468.. option:: LLVM_BUILD_32_BITS:BOOL
469
470 Build 32-bits executables and libraries on 64-bits systems. This option is
Louis Dionneecc89552019-10-01 20:34:50 +0000471 available only on some 64-bits Unix systems. Defaults to OFF.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000472
473.. option:: LLVM_LIT_ARGS:STRING
474
475 Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
476 By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
477 others.
478
479
480Using Alternate ABI libraries
481=============================
482
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400483In order to implement various features like exceptions, RTTI, ``dynamic_cast`` and
484more, libc++ requires what we refer to as an ABI library. Typically, that library
485implements the `Itanium C++ ABI <https://itanium-cxx-abi.github.io/cxx-abi/abi.html>`_.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000486
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400487By default, libc++ uses libc++abi as an ABI library. However, it is possible to use
488other ABI libraries too.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000489
490Using libsupc++ on Linux
491------------------------
492
493You will need libstdc++ in order to provide libsupc++.
494
495Figure out where the libsupc++ headers are on your system. On Ubuntu this
496is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>``
497
498You can also figure this out by running
499
500.. code-block:: bash
501
502 $ echo | g++ -Wp,-v -x c++ - -fsyntax-only
503 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
504 ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
505 #include "..." search starts here:
506 #include &lt;...&gt; search starts here:
507 /usr/include/c++/4.7
508 /usr/include/c++/4.7/x86_64-linux-gnu
509 /usr/include/c++/4.7/backward
510 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
511 /usr/local/include
512 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
513 /usr/include/x86_64-linux-gnu
514 /usr/include
515 End of search list.
516
517Note that the first two entries happen to be what we are looking for. This
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400518may not be correct on all platforms.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000519
520We can now run CMake:
521
522.. code-block:: bash
523
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400524 $ cmake -G Ninja -S llvm -B build \
525 -DLLVM_ENABLE_PROJECTS="libcxx" \
526 -DLIBCXX_CXX_ABI=libstdc++ \
527 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/"
528 $ ninja -C build install-cxx
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000529
530
531You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++``
532above, which will cause the library to be linked to libsupc++ instead
533of libstdc++, but this is only recommended if you know that you will
534never need to link against libstdc++ in the same executable as libc++.
535GCC ships libsupc++ separately but only as a static library. If a
536program also needs to link against libstdc++, it will provide its
537own copy of libsupc++ and this can lead to subtle problems.
538
Eric Fiseliera0733922016-06-02 02:16:28 +0000539Using libcxxrt on Linux
540------------------------
541
542You will need to keep the source tree of `libcxxrt`_ available
543on your build machine and your copy of the libcxxrt shared library must
544be placed where your linker will find it.
545
546We can now run CMake like:
547
548.. code-block:: bash
549
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400550 $ cmake -G Ninja -S llvm -B build \
551 -DLLVM_ENABLE_PROJECTS="libcxx" \
552 -DLIBCXX_CXX_ABI=libcxxrt \
553 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxrt-sources/src
554 $ ninja -C build install-cxx
Eric Fiseliera0733922016-06-02 02:16:28 +0000555
556Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as
557clang is set up to link for libc++ linked to libsupc++. To get around this
558you'll have to set up your linker yourself (or patch clang). For example,
559
560.. code-block:: bash
561
562 $ clang++ -stdlib=libc++ helloworld.cpp \
563 -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc
564
565Alternately, you could just add libcxxrt to your libraries list, which in most
566situations will give the same result:
567
568.. code-block:: bash
569
570 $ clang++ -stdlib=libc++ helloworld.cpp -lcxxrt
571
Louis Dionne4b1b70d2021-07-06 10:39:01 -0400572.. _`libcxxrt`: https://github.com/libcxxrt/libcxxrt