Eric Fiselier | a073392 | 2016-06-02 02:16:28 +0000 | [diff] [blame] | 1 | .. _BuildingLibcxx: |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 2 | |
| 3 | =============== |
| 4 | Building libc++ |
| 5 | =============== |
| 6 | |
| 7 | .. contents:: |
| 8 | :local: |
| 9 | |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 10 | .. _build instructions: |
| 11 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 12 | Getting Started |
| 13 | =============== |
| 14 | |
| 15 | On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install |
| 16 | Xcode 4.2 or later. However if you want to install tip-of-trunk from here |
| 17 | (getting the bleeding edge), read on. |
| 18 | |
| 19 | The basic steps needed to build libc++ are: |
| 20 | |
James Y Knight | f18eebf | 2019-01-29 16:37:27 +0000 | [diff] [blame] | 21 | #. Checkout and configure LLVM (including libc++ and libc++abi), according to the `LLVM |
| 22 | getting started <https://llvm.org/docs/GettingStarted.html>`_ documentation. Make sure |
| 23 | to include ``libcxx`` and ``libcxxabi`` in the ``LLVM_ENABLE_PROJECTS`` option passed |
| 24 | to CMake. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 25 | |
| 26 | For more information about configuring libc++ see :ref:`CMake Options`. |
| 27 | |
| 28 | * ``make cxx`` --- will build libc++ and libc++abi. |
Eric Fiselier | bd40283 | 2016-08-28 18:33:08 +0000 | [diff] [blame] | 29 | * ``make check-cxx check-cxxabi`` --- will run the test suites. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 30 | |
| 31 | Shared libraries for libc++ and libc++ abi should now be present in llvm/build/lib. |
| 32 | See :ref:`using an alternate libc++ installation <alternate libcxx>` |
| 33 | |
| 34 | #. **Optional**: Install libc++ and libc++abi |
| 35 | |
| 36 | If your system already provides a libc++ installation it is important to be |
| 37 | careful not to replace it. Remember Use the CMake option ``CMAKE_INSTALL_PREFIX`` to |
| 38 | select a safe place to install libc++. |
| 39 | |
Eric Fiselier | bd40283 | 2016-08-28 18:33:08 +0000 | [diff] [blame] | 40 | * ``make install-cxx install-cxxabi`` --- Will install the libraries and the headers |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 41 | |
| 42 | .. warning:: |
| 43 | * Replacing your systems libc++ installation could render the system non-functional. |
| 44 | * Mac OS X will not boot without a valid copy of ``libc++.1.dylib`` in ``/usr/lib``. |
| 45 | |
| 46 | |
| 47 | The instructions are for building libc++ on |
| 48 | FreeBSD, Linux, or Mac using `libc++abi`_ as the C++ ABI library. |
| 49 | On Linux, it is also possible to use :ref:`libsupc++ <libsupcxx>` or libcxxrt. |
| 50 | |
James Y Knight | f18eebf | 2019-01-29 16:37:27 +0000 | [diff] [blame] | 51 | It is sometimes beneficial to build separately from the full LLVM build. An |
| 52 | out-of-tree build would look like this: |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 53 | |
| 54 | .. code-block:: bash |
| 55 | |
| 56 | $ cd where-you-want-libcxx-to-live |
James Y Knight | f18eebf | 2019-01-29 16:37:27 +0000 | [diff] [blame] | 57 | $ # Check out the sources (includes everything, but we'll only use libcxx) |
| 58 | $ ``git clone https://github.com/llvm/llvm-project.git`` |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 59 | $ cd where-you-want-to-build |
| 60 | $ mkdir build && cd build |
| 61 | $ export CC=clang CXX=clang++ |
James Y Knight | f18eebf | 2019-01-29 16:37:27 +0000 | [diff] [blame] | 62 | $ cmake -DLLVM_PATH=path/to/separate/llvm \ |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 63 | -DLIBCXX_CXX_ABI=libcxxabi \ |
James Y Knight | f18eebf | 2019-01-29 16:37:27 +0000 | [diff] [blame] | 64 | -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/separate/libcxxabi/include \ |
| 65 | path/to/llvm-project/libcxx |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 66 | $ make |
| 67 | $ make check-libcxx # optional |
| 68 | |
| 69 | |
Saleem Abdulrasool | 3ab0b70 | 2017-02-10 03:58:20 +0000 | [diff] [blame] | 70 | Experimental Support for Windows |
| 71 | -------------------------------- |
| 72 | |
| 73 | The Windows support requires building with clang-cl as cl does not support one |
| 74 | required extension: `#include_next`. Furthermore, VS 2015 or newer (19.00) is |
| 75 | required. In the case of clang-cl, we need to specify the "MS Compatibility |
| 76 | Version" as it defaults to 2014 (18.00). |
| 77 | |
| 78 | CMake + Visual Studio |
| 79 | ~~~~~~~~~~~~~~~~~~~~~ |
| 80 | |
| 81 | Building with Visual Studio currently does not permit running tests. However, |
| 82 | it is the simplest way to build. |
| 83 | |
| 84 | .. code-block:: batch |
| 85 | |
| 86 | > cmake -G "Visual Studio 14 2015" ^ |
| 87 | -T "LLVM-vs2014" ^ |
| 88 | -DLIBCXX_ENABLE_SHARED=YES ^ |
| 89 | -DLIBCXX_ENABLE_STATIC=NO ^ |
| 90 | -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO ^ |
| 91 | \path\to\libcxx |
| 92 | > cmake --build . |
| 93 | |
| 94 | CMake + ninja |
| 95 | ~~~~~~~~~~~~~ |
| 96 | |
| 97 | Building with ninja is required for development to enable tests. |
| 98 | Unfortunately, doing so requires additional configuration as we cannot |
| 99 | just specify a toolset. |
| 100 | |
| 101 | .. code-block:: batch |
| 102 | |
| 103 | > cmake -G Ninja ^ |
| 104 | -DCMAKE_MAKE_PROGRAM=/path/to/ninja ^ |
| 105 | -DCMAKE_SYSTEM_NAME=Windows ^ |
| 106 | -DCMAKE_C_COMPILER=clang-cl ^ |
| 107 | -DCMAKE_C_FLAGS="-fms-compatibility-version=19.00 --target=i686--windows" ^ |
Hamza Sood | 4e2e471 | 2017-12-03 10:18:35 +0000 | [diff] [blame] | 108 | -DCMAKE_CXX_COMPILER=clang-cl ^ |
Saleem Abdulrasool | 3ab0b70 | 2017-02-10 03:58:20 +0000 | [diff] [blame] | 109 | -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.00 --target=i686--windows" ^ |
| 110 | -DLLVM_PATH=/path/to/llvm/tree ^ |
| 111 | -DLIBCXX_ENABLE_SHARED=YES ^ |
| 112 | -DLIBCXX_ENABLE_STATIC=NO ^ |
| 113 | -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=NO ^ |
| 114 | \path\to\libcxx |
| 115 | > /path/to/ninja cxx |
| 116 | > /path/to/ninja check-cxx |
| 117 | |
| 118 | Note that the paths specified with backward slashes must use the `\\` as the |
| 119 | directory separator as clang-cl may otherwise parse the path as an argument. |
| 120 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 121 | .. _`libc++abi`: http://libcxxabi.llvm.org/ |
| 122 | |
| 123 | |
| 124 | .. _CMake Options: |
| 125 | |
| 126 | CMake Options |
| 127 | ============= |
| 128 | |
| 129 | Here are some of the CMake variables that are used often, along with a |
| 130 | brief explanation and LLVM-specific notes. For full documentation, check the |
| 131 | CMake docs or execute ``cmake --help-variable VARIABLE_NAME``. |
| 132 | |
| 133 | **CMAKE_BUILD_TYPE**:STRING |
| 134 | Sets the build type for ``make`` based generators. Possible values are |
| 135 | Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio |
| 136 | the user sets the build type with the IDE settings. |
| 137 | |
| 138 | **CMAKE_INSTALL_PREFIX**:PATH |
| 139 | Path where LLVM will be installed if "make install" is invoked or the |
| 140 | "INSTALL" target is built. |
| 141 | |
| 142 | **CMAKE_CXX_COMPILER**:STRING |
| 143 | The C++ compiler to use when building and testing libc++. |
| 144 | |
| 145 | |
| 146 | .. _libcxx-specific options: |
| 147 | |
| 148 | libc++ specific options |
| 149 | ----------------------- |
| 150 | |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 151 | .. option:: LIBCXX_INSTALL_LIBRARY:BOOL |
| 152 | |
| 153 | **Default**: ``ON`` |
| 154 | |
| 155 | Toggle the installation of the library portion of libc++. |
| 156 | |
| 157 | .. option:: LIBCXX_INSTALL_HEADERS:BOOL |
| 158 | |
| 159 | **Default**: ``ON`` |
| 160 | |
| 161 | Toggle the installation of the libc++ headers. |
| 162 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 163 | .. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL |
| 164 | |
| 165 | **Default**: ``ON`` |
| 166 | |
| 167 | Build libc++ with assertions enabled. |
| 168 | |
| 169 | .. option:: LIBCXX_BUILD_32_BITS:BOOL |
| 170 | |
| 171 | **Default**: ``OFF`` |
| 172 | |
Eric Fiselier | 887b86b | 2016-09-16 03:47:53 +0000 | [diff] [blame] | 173 | Build libc++ as a 32 bit library. Also see `LLVM_BUILD_32_BITS`. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 174 | |
| 175 | .. option:: LIBCXX_ENABLE_SHARED:BOOL |
| 176 | |
| 177 | **Default**: ``ON`` |
| 178 | |
Eric Fiselier | 887b86b | 2016-09-16 03:47:53 +0000 | [diff] [blame] | 179 | Build libc++ as a shared library. Either `LIBCXX_ENABLE_SHARED` or |
| 180 | `LIBCXX_ENABLE_STATIC` has to be enabled. |
Petr Hosek | 1362005 | 2016-08-08 22:57:25 +0000 | [diff] [blame] | 181 | |
| 182 | .. option:: LIBCXX_ENABLE_STATIC:BOOL |
| 183 | |
| 184 | **Default**: ``ON`` |
| 185 | |
Eric Fiselier | 887b86b | 2016-09-16 03:47:53 +0000 | [diff] [blame] | 186 | Build libc++ as a static library. Either `LIBCXX_ENABLE_SHARED` or |
| 187 | `LIBCXX_ENABLE_STATIC` has to be enabled. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 188 | |
| 189 | .. option:: LIBCXX_LIBDIR_SUFFIX:STRING |
| 190 | |
| 191 | Extra suffix to append to the directory where libraries are to be installed. |
Eric Fiselier | 887b86b | 2016-09-16 03:47:53 +0000 | [diff] [blame] | 192 | This option overrides `LLVM_LIBDIR_SUFFIX`. |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 193 | |
Petr Hosek | 3975d8d | 2017-07-11 02:39:50 +0000 | [diff] [blame] | 194 | .. option:: LIBCXX_INSTALL_PREFIX:STRING |
| 195 | |
| 196 | **Default**: ``""`` |
| 197 | |
| 198 | Define libc++ destination prefix. |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 199 | |
Petr Hosek | b42e349 | 2019-01-06 06:14:31 +0000 | [diff] [blame] | 200 | .. option:: LIBCXX_HERMETIC_STATIC_LIBRARY:BOOL |
| 201 | |
| 202 | **Default**: ``OFF`` |
| 203 | |
| 204 | Do not export any symbols from the static libc++ library. This is useful when |
| 205 | This is useful when the static libc++ library is being linked into shared |
| 206 | libraries that may be used in with other shared libraries that use different |
| 207 | C++ library. We want to avoid avoid exporting any libc++ symbols in that case. |
| 208 | |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 209 | .. _libc++experimental options: |
| 210 | |
| 211 | libc++experimental Specific Options |
| 212 | ------------------------------------ |
| 213 | |
| 214 | .. option:: LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL |
| 215 | |
| 216 | **Default**: ``ON`` |
| 217 | |
| 218 | Build and test libc++experimental.a. |
| 219 | |
| 220 | .. option:: LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY:BOOL |
| 221 | |
Eric Fiselier | 121594e | 2016-09-07 01:15:10 +0000 | [diff] [blame] | 222 | **Default**: ``LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY AND LIBCXX_INSTALL_LIBRARY`` |
Eric Fiselier | fa43a5c | 2016-05-03 22:32:08 +0000 | [diff] [blame] | 223 | |
| 224 | Install libc++experimental.a alongside libc++. |
| 225 | |
| 226 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 227 | .. _ABI Library Specific Options: |
| 228 | |
| 229 | ABI Library Specific Options |
| 230 | ---------------------------- |
| 231 | |
| 232 | .. option:: LIBCXX_CXX_ABI:STRING |
| 233 | |
| 234 | **Values**: ``none``, ``libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``. |
| 235 | |
| 236 | Select the ABI library to build libc++ against. |
| 237 | |
| 238 | .. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS |
| 239 | |
| 240 | Provide additional search paths for the ABI library headers. |
| 241 | |
| 242 | .. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH |
| 243 | |
| 244 | Provide the path to the ABI library that libc++ should link against. |
| 245 | |
| 246 | .. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL |
| 247 | |
| 248 | **Default**: ``OFF`` |
| 249 | |
| 250 | If this option is enabled, libc++ will try and link the selected ABI library |
| 251 | statically. |
| 252 | |
Eric Fiselier | 0b09dd1 | 2015-10-15 22:41:51 +0000 | [diff] [blame] | 253 | .. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL |
| 254 | |
| 255 | **Default**: ``ON`` by default on UNIX platforms other than Apple unless |
| 256 | 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``. |
| 257 | |
| 258 | This option generate and installs a linker script as ``libc++.so`` which |
| 259 | links the correct ABI library. |
| 260 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 261 | .. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL |
| 262 | |
| 263 | **Default**: ``OFF`` |
| 264 | |
| 265 | Build and use the LLVM unwinder. Note: This option can only be used when |
| 266 | libc++abi is the C++ ABI library used. |
| 267 | |
| 268 | |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 269 | libc++ Feature Options |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 270 | ---------------------- |
| 271 | |
| 272 | .. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL |
| 273 | |
| 274 | **Default**: ``ON`` |
| 275 | |
| 276 | Build libc++ with exception support. |
| 277 | |
| 278 | .. option:: LIBCXX_ENABLE_RTTI:BOOL |
| 279 | |
| 280 | **Default**: ``ON`` |
| 281 | |
| 282 | Build libc++ with run time type information. |
| 283 | |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 284 | .. option:: LIBCXX_INCLUDE_BENCHMARKS:BOOL |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 285 | |
Eric Fiselier | 93f212c | 2016-08-29 19:50:49 +0000 | [diff] [blame] | 286 | **Default**: ``ON`` |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 287 | |
| 288 | Build the libc++ benchmark tests and the Google Benchmark library needed |
| 289 | to support them. |
| 290 | |
Eric Fiselier | 453bc18 | 2018-11-14 20:38:46 +0000 | [diff] [blame] | 291 | .. option:: LIBCXX_BENCHMARK_TEST_ARGS:STRING |
| 292 | |
| 293 | **Default**: ``--benchmark_min_time=0.01`` |
| 294 | |
| 295 | A semicolon list of arguments to pass when running the libc++ benchmarks using the |
| 296 | ``check-cxx-benchmarks`` rule. By default we run the benchmarks for a very short amount of time, |
| 297 | since the primary use of ``check-cxx-benchmarks`` is to get test and sanitizer coverage, not to |
| 298 | get accurate measurements. |
| 299 | |
Eric Fiselier | 18d2fa3 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 300 | .. option:: LIBCXX_BENCHMARK_NATIVE_STDLIB:STRING |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 301 | |
Eric Fiselier | 18d2fa3 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 302 | **Default**:: ``""`` |
| 303 | |
| 304 | **Values**:: ``libc++``, ``libstdc++`` |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 305 | |
| 306 | Build the libc++ benchmark tests and Google Benchmark library against the |
Eric Fiselier | 18d2fa3 | 2016-10-30 22:53:00 +0000 | [diff] [blame] | 307 | specified standard library on the platform. On linux this can be used to |
| 308 | compare libc++ to libstdc++ by building the benchmark tests against both |
| 309 | standard libraries. |
| 310 | |
| 311 | .. option:: LIBCXX_BENCHMARK_NATIVE_GCC_TOOLCHAIN:STRING |
| 312 | |
| 313 | Use the specified GCC toolchain and standard library when building the native |
| 314 | stdlib benchmark tests. |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 315 | |
Louis Dionne | 1821de4 | 2018-08-16 12:44:28 +0000 | [diff] [blame] | 316 | .. option:: LIBCXX_HIDE_FROM_ABI_PER_TU_BY_DEFAULT:BOOL |
| 317 | |
| 318 | **Default**: ``OFF`` |
| 319 | |
| 320 | Pick the default for whether to constrain ABI-unstable symbols to |
| 321 | each individual translation unit. This setting controls whether |
| 322 | `_LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT` is defined by default -- |
| 323 | see the documentation of that macro for details. |
| 324 | |
Eric Fiselier | 9e3e137 | 2016-07-19 23:07:03 +0000 | [diff] [blame] | 325 | |
| 326 | libc++ ABI Feature Options |
| 327 | -------------------------- |
Evgeniy Stepanov | da2ff7e | 2015-10-13 23:48:28 +0000 | [diff] [blame] | 328 | |
| 329 | The following options allow building libc++ for a different ABI version. |
| 330 | |
| 331 | .. option:: LIBCXX_ABI_VERSION:STRING |
| 332 | |
| 333 | **Default**: ``1`` |
| 334 | |
| 335 | Defines the target ABI version of libc++. |
| 336 | |
| 337 | .. option:: LIBCXX_ABI_UNSTABLE:BOOL |
| 338 | |
| 339 | **Default**: ``OFF`` |
| 340 | |
| 341 | Build the "unstable" ABI version of libc++. Includes all ABI changing features |
| 342 | on top of the current stable version. |
| 343 | |
Eric Fiselier | b33778a | 2018-10-30 21:44:53 +0000 | [diff] [blame] | 344 | .. option:: LIBCXX_ABI_NAMESPACE:STRING |
| 345 | |
| 346 | **Default**: ``__n`` where ``n`` is the current ABI version. |
| 347 | |
| 348 | This option defines the name of the inline ABI versioning namespace. It can be used for building |
| 349 | custom versions of libc++ with unique symbol names in order to prevent conflicts or ODR issues |
| 350 | with other libc++ versions. |
| 351 | |
| 352 | .. warning:: |
| 353 | When providing a custom namespace, it's the users responsibility to ensure the name won't cause |
Louis Dionne | 6f2c6fb | 2018-11-16 14:57:47 +0000 | [diff] [blame] | 354 | conflicts with other names defined by libc++, both now and in the future. In particular, inline |
| 355 | namespaces of the form ``__[0-9]+`` are strictly reserved by libc++ and may not be used by users. |
| 356 | Doing otherwise could cause conflicts and hinder libc++ ABI evolution. |
Eric Fiselier | b33778a | 2018-10-30 21:44:53 +0000 | [diff] [blame] | 357 | |
Shoaib Meenai | 4ca4b7c | 2017-10-04 23:17:12 +0000 | [diff] [blame] | 358 | .. option:: LIBCXX_ABI_DEFINES:STRING |
| 359 | |
| 360 | **Default**: ``""`` |
| 361 | |
| 362 | A semicolon-separated list of ABI macros to persist in the site config header. |
| 363 | See ``include/__config`` for the list of ABI macros. |
| 364 | |
Eric Fiselier | d720d1f | 2015-08-22 19:40:49 +0000 | [diff] [blame] | 365 | .. _LLVM-specific variables: |
| 366 | |
| 367 | LLVM-specific options |
| 368 | --------------------- |
| 369 | |
| 370 | .. option:: LLVM_LIBDIR_SUFFIX:STRING |
| 371 | |
| 372 | Extra suffix to append to the directory where libraries are to be |
| 373 | installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` |
| 374 | to install libraries to ``/usr/lib64``. |
| 375 | |
| 376 | .. option:: LLVM_BUILD_32_BITS:BOOL |
| 377 | |
| 378 | Build 32-bits executables and libraries on 64-bits systems. This option is |
| 379 | available only on some 64-bits unix systems. Defaults to OFF. |
| 380 | |
| 381 | .. option:: LLVM_LIT_ARGS:STRING |
| 382 | |
| 383 | Arguments given to lit. ``make check`` and ``make clang-test`` are affected. |
| 384 | By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on |
| 385 | others. |
| 386 | |
| 387 | |
| 388 | Using Alternate ABI libraries |
| 389 | ============================= |
| 390 | |
| 391 | |
| 392 | .. _libsupcxx: |
| 393 | |
| 394 | Using libsupc++ on Linux |
| 395 | ------------------------ |
| 396 | |
| 397 | You will need libstdc++ in order to provide libsupc++. |
| 398 | |
| 399 | Figure out where the libsupc++ headers are on your system. On Ubuntu this |
| 400 | is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>`` |
| 401 | |
| 402 | You can also figure this out by running |
| 403 | |
| 404 | .. code-block:: bash |
| 405 | |
| 406 | $ echo | g++ -Wp,-v -x c++ - -fsyntax-only |
| 407 | ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" |
| 408 | ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include" |
| 409 | #include "..." search starts here: |
| 410 | #include <...> search starts here: |
| 411 | /usr/include/c++/4.7 |
| 412 | /usr/include/c++/4.7/x86_64-linux-gnu |
| 413 | /usr/include/c++/4.7/backward |
| 414 | /usr/lib/gcc/x86_64-linux-gnu/4.7/include |
| 415 | /usr/local/include |
| 416 | /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed |
| 417 | /usr/include/x86_64-linux-gnu |
| 418 | /usr/include |
| 419 | End of search list. |
| 420 | |
| 421 | Note that the first two entries happen to be what we are looking for. This |
| 422 | may not be correct on other platforms. |
| 423 | |
| 424 | We can now run CMake: |
| 425 | |
| 426 | .. code-block:: bash |
| 427 | |
| 428 | $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \ |
| 429 | -DLIBCXX_CXX_ABI=libstdc++ \ |
| 430 | -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" \ |
| 431 | -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \ |
| 432 | <libc++-source-dir> |
| 433 | |
| 434 | |
| 435 | You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++`` |
| 436 | above, which will cause the library to be linked to libsupc++ instead |
| 437 | of libstdc++, but this is only recommended if you know that you will |
| 438 | never need to link against libstdc++ in the same executable as libc++. |
| 439 | GCC ships libsupc++ separately but only as a static library. If a |
| 440 | program also needs to link against libstdc++, it will provide its |
| 441 | own copy of libsupc++ and this can lead to subtle problems. |
| 442 | |
| 443 | .. code-block:: bash |
| 444 | |
| 445 | $ make cxx |
| 446 | $ make install |
| 447 | |
| 448 | You can now run clang with -stdlib=libc++. |
Eric Fiselier | a073392 | 2016-06-02 02:16:28 +0000 | [diff] [blame] | 449 | |
| 450 | |
| 451 | .. _libcxxrt_ref: |
| 452 | |
| 453 | Using libcxxrt on Linux |
| 454 | ------------------------ |
| 455 | |
| 456 | You will need to keep the source tree of `libcxxrt`_ available |
| 457 | on your build machine and your copy of the libcxxrt shared library must |
| 458 | be placed where your linker will find it. |
| 459 | |
| 460 | We can now run CMake like: |
| 461 | |
| 462 | .. code-block:: bash |
| 463 | |
| 464 | $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \ |
| 465 | -DLIBCXX_CXX_ABI=libcxxrt \ |
| 466 | -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxrt-sources/src \ |
| 467 | -DCMAKE_BUILD_TYPE=Release \ |
| 468 | -DCMAKE_INSTALL_PREFIX=/usr \ |
| 469 | <libc++-source-directory> |
| 470 | $ make cxx |
| 471 | $ make install |
| 472 | |
| 473 | Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as |
| 474 | clang is set up to link for libc++ linked to libsupc++. To get around this |
| 475 | you'll have to set up your linker yourself (or patch clang). For example, |
| 476 | |
| 477 | .. code-block:: bash |
| 478 | |
| 479 | $ clang++ -stdlib=libc++ helloworld.cpp \ |
| 480 | -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc |
| 481 | |
| 482 | Alternately, you could just add libcxxrt to your libraries list, which in most |
| 483 | situations will give the same result: |
| 484 | |
| 485 | .. code-block:: bash |
| 486 | |
| 487 | $ clang++ -stdlib=libc++ helloworld.cpp -lcxxrt |
| 488 | |
| 489 | .. _`libcxxrt`: https://github.com/pathscale/libcxxrt/ |
| 490 | |
| 491 | |
| 492 | Using a local ABI library installation |
| 493 | --------------------------------------- |
| 494 | |
| 495 | .. warning:: |
| 496 | This is not recommended in almost all cases. |
| 497 | |
| 498 | These instructions should only be used when you can't install your ABI library. |
| 499 | |
| 500 | Normally you must link libc++ against a ABI shared library that the |
| 501 | linker can find. If you want to build and test libc++ against an ABI |
| 502 | library not in the linker's path you needq to set |
| 503 | ``-DLIBCXX_CXX_ABI_LIBRARY_PATH=/path/to/abi/lib`` when configuring CMake. |
| 504 | |
| 505 | An example build using libc++abi would look like: |
| 506 | |
| 507 | .. code-block:: bash |
| 508 | |
| 509 | $ CC=clang CXX=clang++ cmake \ |
| 510 | -DLIBCXX_CXX_ABI=libc++abi \ |
| 511 | -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/path/to/libcxxabi/include" \ |
| 512 | -DLIBCXX_CXX_ABI_LIBRARY_PATH="/path/to/libcxxabi-build/lib" \ |
| 513 | path/to/libcxx |
| 514 | $ make |
| 515 | |
| 516 | When testing libc++ LIT will automatically link against the proper ABI |
| 517 | library. |