blob: b1fd19a481a52458d47f1270f5efbbac8a8ef114 [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
Eric Fiselierd720d1f2015-08-22 19:40:49 +000012Getting Started
13===============
14
15On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install
16Xcode 4.2 or later. However if you want to install tip-of-trunk from here
17(getting the bleeding edge), read on.
18
Dan Albert08302aa2019-11-07 12:40:05 -080019The following instructions describe how to checkout, build, test and
20(optionally) install libc++ and libc++abi.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000021
Dan Albert08302aa2019-11-07 12:40:05 -080022If your system already provides a libc++ installation it is important to be
23careful not to replace it. Remember Use the CMake option
24``CMAKE_INSTALL_PREFIX`` to select a safe place to install libc++.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000025
Dan Albert08302aa2019-11-07 12:40:05 -080026.. warning::
27 * Replacing your systems libc++ installation could render the system non-functional.
28 * macOS will not boot without a valid copy of ``libc++.1.dylib`` in ``/usr/lib``.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000029
Dan Albert08302aa2019-11-07 12:40:05 -080030.. code-block:: bash
Eric Fiselierd720d1f2015-08-22 19:40:49 +000031
Dan Albert08302aa2019-11-07 12:40:05 -080032 $ git clone https://github.com/llvm/llvm-project.git
33 $ cd llvm-project
34 $ mkdir build && cd build
35 $ cmake -DCMAKE_C_COMPILER=clang \
36 -DCMAKE_CXX_COMPILER=clang++ \
37 -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \
38 ../llvm
39 $ make # Build
40 $ make check-cxx # Test
41 $ make install-cxx install-cxxabi # Install
Eric Fiselierd720d1f2015-08-22 19:40:49 +000042
Dan Albert08302aa2019-11-07 12:40:05 -080043For more information about configuring libc++ see :ref:`CMake Options`. You may
44also want to read the `LLVM getting started
45<https://llvm.org/docs/GettingStarted.html>`_ documentation.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000046
Dan Albert08302aa2019-11-07 12:40:05 -080047Shared libraries for libc++ and libc++ abi should now be present in
48``build/lib``. See :ref:`using an alternate libc++ installation <alternate
49libcxx>` for information on how to use this libc++.
Eric Fiselierd720d1f2015-08-22 19:40:49 +000050
51The instructions are for building libc++ on
52FreeBSD, Linux, or Mac using `libc++abi`_ as the C++ ABI library.
53On Linux, it is also possible to use :ref:`libsupc++ <libsupcxx>` or libcxxrt.
54
Louis Dionnea7336b12020-06-29 12:25:10 -040055It is possible to build libc++ standalone (i.e. without building other LLVM
56projects). A standalone build would look like this:
Eric Fiselierd720d1f2015-08-22 19:40:49 +000057
58.. code-block:: bash
59
Louis Dionnea7336b12020-06-29 12:25:10 -040060 $ git clone https://github.com/llvm/llvm-project.git llvm-project
61 $ cd llvm-project
Eric Fiselierd720d1f2015-08-22 19:40:49 +000062 $ mkdir build && cd build
Louis Dionnea7336b12020-06-29 12:25:10 -040063 $ cmake -DCMAKE_C_COMPILER=clang \
64 -DCMAKE_CXX_COMPILER=clang++ \
Eric Fiselierd720d1f2015-08-22 19:40:49 +000065 -DLIBCXX_CXX_ABI=libcxxabi \
James Y Knightf18eebf2019-01-29 16:37:27 +000066 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/separate/libcxxabi/include \
Louis Dionnea7336b12020-06-29 12:25:10 -040067 ../libcxx
Eric Fiselierd720d1f2015-08-22 19:40:49 +000068 $ make
Louis Dionnef58d8292020-03-11 17:03:00 -040069 $ make check-cxx # optional
Eric Fiselierd720d1f2015-08-22 19:40:49 +000070
71
Martin Storsjöf9535f72021-02-22 01:20:28 +020072Support for Windows
73-------------------
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000074
Martin Storsjöf9535f72021-02-22 01:20:28 +020075libcxx supports being built with clang-cl, but not with MSVC's cl.exe, as
76cl doesn't support the `#include_next` extension. Furthermore, VS 2017 or
77newer (19.14) is required.
78
79libcxx also supports being built with clang targeting MinGW environments.
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000080
81CMake + Visual Studio
82~~~~~~~~~~~~~~~~~~~~~
83
84Building with Visual Studio currently does not permit running tests. However,
85it is the simplest way to build.
86
87.. code-block:: batch
88
Martin Storsjöf9535f72021-02-22 01:20:28 +020089 > cmake -G "Visual Studio 16 2019" ^
90 -T "ClangCL" ^
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000091 -DLIBCXX_ENABLE_SHARED=YES ^
92 -DLIBCXX_ENABLE_STATIC=NO ^
93 -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO ^
94 \path\to\libcxx
95 > cmake --build .
96
Martin Storsjöf9535f72021-02-22 01:20:28 +020097CMake + ninja (MSVC)
98~~~~~~~~~~~~~~~~~~~~
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +000099
100Building with ninja is required for development to enable tests.
Martin Storsjöf9535f72021-02-22 01:20:28 +0200101Running the tests also requires a Bash shell and Python to be available.
102
103If Git for Windows is available, that can be used to provide the bash
104shell by adding the right bin directory to the path, e.g.
105`set PATH=%PATH%;C:\Program Files\Git\usr\bin`.
106
107Alternatively, one can also choose to run the whole build in a MSYS2
108shell. That can be set up e.g. by starting a Visual Studio Tools Command
109Prompt (for getting the environment variables pointing to the headers and
110import libraries), and making sure that clang-cl is available in the
111path. From there, launch an MSYS2 shell via e.g.
112`C:\msys64\msys2_shell.cmd -full-path -mingw64` (preserving the earlier
113environment, allowing the MSVC headers/libraries and clang-cl to be found).
114
115In either case, then run:
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000116
117.. code-block:: batch
118
119 > cmake -G Ninja ^
Martin Storsjöf9535f72021-02-22 01:20:28 +0200120 -DCMAKE_BUILD_TYPE=Release ^
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000121 -DCMAKE_C_COMPILER=clang-cl ^
Martin Storsjöf9535f72021-02-22 01:20:28 +0200122 -DCMAKE_CXX_COMPILER=clang-cl ^
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000123 -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO ^
Martin Storsjöf9535f72021-02-22 01:20:28 +0200124 path/to/libcxx
125 > ninja cxx
126 > ninja check-cxx
Saleem Abdulrasool3ab0b702017-02-10 03:58:20 +0000127
Martin Storsjöf9535f72021-02-22 01:20:28 +0200128If you are running in an MSYS2 shell and you have installed the
129MSYS2-provided clang package (which defaults to a non-MSVC target), you
130should add e.g. `-DLIBCXX_TARGET_TRIPLE=x86_64-windows-msvc` (replacing
131`x86_64` with the architecture you're targeting) to the `cmake` command
132line above. This will instruct `check-cxx` to use the right target triple
133when invoking `clang++`.
134
135Also note that if not building in Release mode, a failed assert in the tests
136pops up a blocking dialog box, making it hard to run a larger number of tests.
137
138CMake + ninja (MinGW)
139~~~~~~~~~~~~~~~~~~~~~
140
141libcxx can also be built in MinGW environments, e.g. with the MinGW
142compilers in MSYS2. This requires clang to be available (installed with
143e.g. the `mingw-w64-x86_64-clang` package), together with CMake and ninja.
144
145.. code-block:: bash
146
147 > cmake -G Ninja \
148 -DCMAKE_C_COMPILER=clang \
149 -DCMAKE_CXX_COMPILER=clang++ \
150 -DLIBCXX_HAS_WIN32_THREAD_API=ON \
151 -DLIBCXX_CXX_ABI=libstdc++ \
152 -DLIBCXX_TARGET_INFO="libcxx.test.target_info.MingwLocalTI" \
153 path/to/libcxx
154 > ninja cxx
155 > cp /mingw64/bin/{libstdc++-6,libgcc_s_seh-1,libwinpthread-1}.dll lib
156 > ninja check-cxx
157
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 Hosek3975d8d2017-07-11 02:39:50 +0000238.. option:: LIBCXX_INSTALL_PREFIX:STRING
239
240 **Default**: ``""``
241
242 Define libc++ destination prefix.
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000243
Petr Hosekb42e3492019-01-06 06:14:31 +0000244.. option:: LIBCXX_HERMETIC_STATIC_LIBRARY:BOOL
245
246 **Default**: ``OFF``
247
Jonathan Metzmance2328d2019-04-10 23:44:27 +0000248 Do not export any symbols from the static libc++ library.
Petr Hosekb42e3492019-01-06 06:14:31 +0000249 This is useful when the static libc++ library is being linked into shared
250 libraries that may be used in with other shared libraries that use different
Louis Dionned0889672019-08-23 19:42:09 +0000251 C++ library. We want to avoid exporting any libc++ symbols in that case.
Petr Hosekb42e3492019-01-06 06:14:31 +0000252
Eric Fiselier72e2dd82019-03-21 00:04:31 +0000253.. option:: LIBCXX_ENABLE_FILESYSTEM:BOOL
254
255 **Default**: ``ON`` except on Windows.
256
257 This option can be used to enable or disable the filesystem components on
258 platforms that may not support them. For example on Windows.
259
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000260.. _libc++experimental options:
261
262libc++experimental Specific Options
263------------------------------------
264
265.. option:: LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL
266
267 **Default**: ``ON``
268
269 Build and test libc++experimental.a.
270
271.. option:: LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY:BOOL
272
Eric Fiselier121594e2016-09-07 01:15:10 +0000273 **Default**: ``LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY AND LIBCXX_INSTALL_LIBRARY``
Eric Fiselierfa43a5c2016-05-03 22:32:08 +0000274
275 Install libc++experimental.a alongside libc++.
276
277
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000278.. _ABI Library Specific Options:
279
280ABI Library Specific Options
281----------------------------
282
283.. option:: LIBCXX_CXX_ABI:STRING
284
285 **Values**: ``none``, ``libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``.
286
287 Select the ABI library to build libc++ against.
288
289.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS
290
291 Provide additional search paths for the ABI library headers.
292
293.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH
294
295 Provide the path to the ABI library that libc++ should link against.
296
297.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL
298
299 **Default**: ``OFF``
300
301 If this option is enabled, libc++ will try and link the selected ABI library
302 statically.
303
Eric Fiselier0b09dd12015-10-15 22:41:51 +0000304.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL
305
306 **Default**: ``ON`` by default on UNIX platforms other than Apple unless
307 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``.
308
309 This option generate and installs a linker script as ``libc++.so`` which
310 links the correct ABI library.
311
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000312.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
313
314 **Default**: ``OFF``
315
316 Build and use the LLVM unwinder. Note: This option can only be used when
317 libc++abi is the C++ ABI library used.
318
319
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000320libc++ Feature Options
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000321----------------------
322
323.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
324
325 **Default**: ``ON``
326
327 Build libc++ with exception support.
328
329.. option:: LIBCXX_ENABLE_RTTI:BOOL
330
331 **Default**: ``ON``
332
333 Build libc++ with run time type information.
334
Saleem Abdulrasool1e06a1d2019-07-04 19:08:16 +0000335.. option:: LIBCXX_INCLUDE_TESTS:BOOL
336
Nico Weberf1038c22021-02-18 11:58:48 -0500337 **Default**: ``ON`` (or value of ``LLVM_INCLUDE_TESTS``)
Saleem Abdulrasool1e06a1d2019-07-04 19:08:16 +0000338
339 Build the libc++ tests.
340
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000341.. option:: LIBCXX_INCLUDE_BENCHMARKS:BOOL
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000342
Eric Fiselier93f212c2016-08-29 19:50:49 +0000343 **Default**: ``ON``
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000344
345 Build the libc++ benchmark tests and the Google Benchmark library needed
346 to support them.
347
Eric Fiselier453bc182018-11-14 20:38:46 +0000348.. option:: LIBCXX_BENCHMARK_TEST_ARGS:STRING
349
350 **Default**: ``--benchmark_min_time=0.01``
351
352 A semicolon list of arguments to pass when running the libc++ benchmarks using the
353 ``check-cxx-benchmarks`` rule. By default we run the benchmarks for a very short amount of time,
354 since the primary use of ``check-cxx-benchmarks`` is to get test and sanitizer coverage, not to
355 get accurate measurements.
356
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000357.. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000358
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000359 **Default**:: ``""``
360
361 **Values**:: ``libc++``, ``libstdc++``
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000362
363 Build the libc++ benchmark tests and Google Benchmark library against the
Louis Dionneecc89552019-10-01 20:34:50 +0000364 specified standard library on the platform. On Linux this can be used to
Eric Fiselier18d2fa32016-10-30 22:53:00 +0000365 compare libc++ to libstdc++ by building the benchmark tests against both
366 standard libraries.
367
368.. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING
369
370 Use the specified GCC toolchain and standard library when building the native
371 stdlib benchmark tests.
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000372
Louis Dionne1821de42018-08-16 12:44:28 +0000373.. option:: LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT:BOOL
374
375 **Default**: ``OFF``
376
377 Pick the default for whether to constrain ABI-unstable symbols to
378 each individual translation unit. This setting controls whether
379 `_LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT` is defined by default --
380 see the documentation of that macro for details.
381
Eric Fiselier9e3e1372016-07-19 23:07:03 +0000382
383libc++ ABI Feature Options
384--------------------------
Evgeniy Stepanovda2ff7e2015-10-13 23:48:28 +0000385
386The following options allow building libc++ for a different ABI version.
387
388.. option:: LIBCXX_ABI_VERSION:STRING
389
390 **Default**: ``1``
391
392 Defines the target ABI version of libc++.
393
394.. option:: LIBCXX_ABI_UNSTABLE:BOOL
395
396 **Default**: ``OFF``
397
398 Build the "unstable" ABI version of libc++. Includes all ABI changing features
399 on top of the current stable version.
400
Eric Fiselierb33778a2018-10-30 21:44:53 +0000401.. option:: LIBCXX_ABI_NAMESPACE:STRING
402
403 **Default**: ``__n`` where ``n`` is the current ABI version.
404
405 This option defines the name of the inline ABI versioning namespace. It can be used for building
406 custom versions of libc++ with unique symbol names in order to prevent conflicts or ODR issues
407 with other libc++ versions.
408
409 .. warning::
410 When providing a custom namespace, it's the users responsibility to ensure the name won't cause
Louis Dionne6f2c6fb2018-11-16 14:57:47 +0000411 conflicts with other names defined by libc++, both now and in the future. In particular, inline
412 namespaces of the form ``__[0-9]+`` are strictly reserved by libc++ and may not be used by users.
413 Doing otherwise could cause conflicts and hinder libc++ ABI evolution.
Eric Fiselierb33778a2018-10-30 21:44:53 +0000414
Shoaib Meenai4ca4b7c2017-10-04 23:17:12 +0000415.. option:: LIBCXX_ABI_DEFINES:STRING
416
417 **Default**: ``""``
418
419 A semicolon-separated list of ABI macros to persist in the site config header.
420 See ``include/__config`` for the list of ABI macros.
421
Eric Fiselierf3566292019-05-29 02:21:37 +0000422
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000423.. _LLVM-specific variables:
424
425LLVM-specific options
426---------------------
427
428.. option:: LLVM_LIBDIR_SUFFIX:STRING
429
430 Extra suffix to append to the directory where libraries are to be
431 installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
432 to install libraries to ``/usr/lib64``.
433
434.. option:: LLVM_BUILD_32_BITS:BOOL
435
436 Build 32-bits executables and libraries on 64-bits systems. This option is
Louis Dionneecc89552019-10-01 20:34:50 +0000437 available only on some 64-bits Unix systems. Defaults to OFF.
Eric Fiselierd720d1f2015-08-22 19:40:49 +0000438
439.. option:: LLVM_LIT_ARGS:STRING
440
441 Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
442 By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
443 others.
444
445
446Using Alternate ABI libraries
447=============================
448
449
450.. _libsupcxx:
451
452Using libsupc++ on Linux
453------------------------
454
455You will need libstdc++ in order to provide libsupc++.
456
457Figure out where the libsupc++ headers are on your system. On Ubuntu this
458is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>``
459
460You can also figure this out by running
461
462.. code-block:: bash
463
464 $ echo | g++ -Wp,-v -x c++ - -fsyntax-only
465 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
466 ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
467 #include "..." search starts here:
468 #include &lt;...&gt; search starts here:
469 /usr/include/c++/4.7
470 /usr/include/c++/4.7/x86_64-linux-gnu
471 /usr/include/c++/4.7/backward
472 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
473 /usr/local/include
474 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
475 /usr/include/x86_64-linux-gnu
476 /usr/include
477 End of search list.
478
479Note that the first two entries happen to be what we are looking for. This
480may not be correct on other platforms.
481
482We can now run CMake:
483
484.. code-block:: bash
485
486 $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \
487 -DLIBCXX_CXX_ABI=libstdc++ \
488 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" \
489 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
490 <libc++-source-dir>
491
492
493You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++``
494above, which will cause the library to be linked to libsupc++ instead
495of libstdc++, but this is only recommended if you know that you will
496never need to link against libstdc++ in the same executable as libc++.
497GCC ships libsupc++ separately but only as a static library. If a
498program also needs to link against libstdc++, it will provide its
499own copy of libsupc++ and this can lead to subtle problems.
500
501.. code-block:: bash
502
503 $ make cxx
504 $ make install
505
506You can now run clang with -stdlib=libc++.
Eric Fiseliera0733922016-06-02 02:16:28 +0000507
508
509.. _libcxxrt_ref:
510
511Using libcxxrt on Linux
512------------------------
513
514You will need to keep the source tree of `libcxxrt`_ available
515on your build machine and your copy of the libcxxrt shared library must
516be placed where your linker will find it.
517
518We can now run CMake like:
519
520.. code-block:: bash
521
522 $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \
523 -DLIBCXX_CXX_ABI=libcxxrt \
524 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxrt-sources/src \
525 -DCMAKE_BUILD_TYPE=Release \
526 -DCMAKE_INSTALL_PREFIX=/usr \
527 <libc++-source-directory>
528 $ make cxx
529 $ make install
530
531Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as
532clang is set up to link for libc++ linked to libsupc++. To get around this
533you'll have to set up your linker yourself (or patch clang). For example,
534
535.. code-block:: bash
536
537 $ clang++ -stdlib=libc++ helloworld.cpp \
538 -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc
539
540Alternately, you could just add libcxxrt to your libraries list, which in most
541situations will give the same result:
542
543.. code-block:: bash
544
545 $ clang++ -stdlib=libc++ helloworld.cpp -lcxxrt
546
547.. _`libcxxrt`: https://github.com/pathscale/libcxxrt/
548
549
550Using a local ABI library installation
551---------------------------------------
552
553.. warning::
554 This is not recommended in almost all cases.
555
556These instructions should only be used when you can't install your ABI library.
557
558Normally you must link libc++ against a ABI shared library that the
559linker can find. If you want to build and test libc++ against an ABI
Louis Dionneecc89552019-10-01 20:34:50 +0000560library not in the linker's path you need to set
Eric Fiseliera0733922016-06-02 02:16:28 +0000561``-DLIBCXX_CXX_ABI_LIBRARY_PATH=/path/to/abi/lib`` when configuring CMake.
562
563An example build using libc++abi would look like:
564
565.. code-block:: bash
566
567 $ CC=clang CXX=clang++ cmake \
568 -DLIBCXX_CXX_ABI=libc++abi \
569 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/path/to/libcxxabi/include" \
570 -DLIBCXX_CXX_ABI_LIBRARY_PATH="/path/to/libcxxabi-build/lib" \
571 path/to/libcxx
572 $ make
573
574When testing libc++ LIT will automatically link against the proper ABI
575library.