blob: 36866b13ef7bd28fca02f7843f50afc558f6ea56 [file] [log] [blame]
Eric Fiselierd2562802016-06-02 02:16:28 +00001.. _BuildingLibcxx:
Eric Fiselierb9f425a2015-08-22 19:40:49 +00002
3===============
4Building libc++
5===============
6
7.. contents::
8 :local:
9
Eric Fiselier7039fa12016-05-03 22:32:08 +000010.. _build instructions:
11
Eric Fiselierb9f425a2015-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
19The basic steps needed to build libc++ are:
20
21#. Checkout LLVM:
22
23 * ``cd where-you-want-llvm-to-live``
24 * ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
25
26#. Checkout libc++:
27
28 * ``cd where-you-want-llvm-to-live``
Eric Fiselier8459d202015-12-14 22:26:28 +000029 * ``cd llvm/projects``
Eric Fiselierb9f425a2015-08-22 19:40:49 +000030 * ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx``
31
32#. Checkout libc++abi:
33
34 * ``cd where-you-want-llvm-to-live``
35 * ``cd llvm/projects``
Eric Fiselier8459d202015-12-14 22:26:28 +000036 * ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi``
Eric Fiselierb9f425a2015-08-22 19:40:49 +000037
38#. Configure and build libc++ with libc++abi:
39
Alexey Samsonovd118e322016-01-30 01:11:42 +000040 CMake is the only supported configuration system.
Eric Fiselierb9f425a2015-08-22 19:40:49 +000041
42 Clang is the preferred compiler when building and using libc++.
43
44 * ``cd where you want to build llvm``
45 * ``mkdir build``
46 * ``cd build``
47 * ``cmake -G <generator> [options] <path to llvm sources>``
48
49 For more information about configuring libc++ see :ref:`CMake Options`.
50
51 * ``make cxx`` --- will build libc++ and libc++abi.
52 * ``make check-libcxx check-libcxxabi`` --- will run the test suites.
53
54 Shared libraries for libc++ and libc++ abi should now be present in llvm/build/lib.
55 See :ref:`using an alternate libc++ installation <alternate libcxx>`
56
57#. **Optional**: Install libc++ and libc++abi
58
59 If your system already provides a libc++ installation it is important to be
60 careful not to replace it. Remember Use the CMake option ``CMAKE_INSTALL_PREFIX`` to
61 select a safe place to install libc++.
62
63 * ``make install-libcxx install-libcxxabi`` --- Will install the libraries and the headers
64
65 .. warning::
66 * Replacing your systems libc++ installation could render the system non-functional.
67 * Mac OS X will not boot without a valid copy of ``libc++.1.dylib`` in ``/usr/lib``.
68
69
70The instructions are for building libc++ on
71FreeBSD, Linux, or Mac using `libc++abi`_ as the C++ ABI library.
72On Linux, it is also possible to use :ref:`libsupc++ <libsupcxx>` or libcxxrt.
73
Eric Fiselierb22481a2015-09-06 23:31:16 +000074It is sometimes beneficial to build outside of the LLVM tree. An out-of-tree
75build would look like this:
Eric Fiselierb9f425a2015-08-22 19:40:49 +000076
77.. code-block:: bash
78
79 $ cd where-you-want-libcxx-to-live
80 $ # Check out llvm, libc++ and libc++abi.
81 $ ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
82 $ ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx``
83 $ ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi``
84 $ cd where-you-want-to-build
85 $ mkdir build && cd build
86 $ export CC=clang CXX=clang++
87 $ cmake -DLLVM_PATH=path/to/llvm \
88 -DLIBCXX_CXX_ABI=libcxxabi \
89 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxabi/include \
90 path/to/libcxx
91 $ make
92 $ make check-libcxx # optional
93
94
95.. _`libc++abi`: http://libcxxabi.llvm.org/
96
97
98.. _CMake Options:
99
100CMake Options
101=============
102
103Here are some of the CMake variables that are used often, along with a
104brief explanation and LLVM-specific notes. For full documentation, check the
105CMake docs or execute ``cmake --help-variable VARIABLE_NAME``.
106
107**CMAKE_BUILD_TYPE**:STRING
108 Sets the build type for ``make`` based generators. Possible values are
109 Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio
110 the user sets the build type with the IDE settings.
111
112**CMAKE_INSTALL_PREFIX**:PATH
113 Path where LLVM will be installed if "make install" is invoked or the
114 "INSTALL" target is built.
115
116**CMAKE_CXX_COMPILER**:STRING
117 The C++ compiler to use when building and testing libc++.
118
119
120.. _libcxx-specific options:
121
122libc++ specific options
123-----------------------
124
Eric Fiselier7039fa12016-05-03 22:32:08 +0000125.. option:: LIBCXX_INSTALL_LIBRARY:BOOL
126
127 **Default**: ``ON``
128
129 Toggle the installation of the library portion of libc++.
130
131.. option:: LIBCXX_INSTALL_HEADERS:BOOL
132
133 **Default**: ``ON``
134
135 Toggle the installation of the libc++ headers.
136
Eric Fiselierb9f425a2015-08-22 19:40:49 +0000137.. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL
138
139 **Default**: ``ON``
140
141 Build libc++ with assertions enabled.
142
143.. option:: LIBCXX_BUILD_32_BITS:BOOL
144
145 **Default**: ``OFF``
146
147 Build libc++ as a 32 bit library. Also see :option:`LLVM_BUILD_32_BITS`.
148
149.. option:: LIBCXX_ENABLE_SHARED:BOOL
150
151 **Default**: ``ON``
152
153 Build libc++ as a shared library. If ``OFF`` is specified then libc++ is
154 built as a static library.
155
156.. option:: LIBCXX_LIBDIR_SUFFIX:STRING
157
158 Extra suffix to append to the directory where libraries are to be installed.
159 This option overrides :option:`LLVM_LIBDIR_SUFFIX`.
160
Eric Fiselier7039fa12016-05-03 22:32:08 +0000161
162.. _libc++experimental options:
163
164libc++experimental Specific Options
165------------------------------------
166
167.. option:: LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL
168
169 **Default**: ``ON``
170
171 Build and test libc++experimental.a.
172
173.. option:: LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY:BOOL
174
175 **Default**: ``OFF``
176
177 Install libc++experimental.a alongside libc++.
178
179
Eric Fiselier6e9a6942016-06-17 19:46:40 +0000180.. option:: LIBCXX_ENABLE_FILESYSTEM:BOOL
181
182 **Default**: ``LIBCXX_ENABLE_EXPERIMENTAL_LIBRARY``
183
184 Build filesystem as part of libc++experimental.a. This allows filesystem
185 to be disabled without turning off the entire experimental library.
186
187
Eric Fiselierb9f425a2015-08-22 19:40:49 +0000188.. _ABI Library Specific Options:
189
190ABI Library Specific Options
191----------------------------
192
193.. option:: LIBCXX_CXX_ABI:STRING
194
195 **Values**: ``none``, ``libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``.
196
197 Select the ABI library to build libc++ against.
198
199.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS
200
201 Provide additional search paths for the ABI library headers.
202
203.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH
204
205 Provide the path to the ABI library that libc++ should link against.
206
207.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL
208
209 **Default**: ``OFF``
210
211 If this option is enabled, libc++ will try and link the selected ABI library
212 statically.
213
Eric Fiselierbb856cc2015-10-15 22:41:51 +0000214.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL
215
216 **Default**: ``ON`` by default on UNIX platforms other than Apple unless
217 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``.
218
219 This option generate and installs a linker script as ``libc++.so`` which
220 links the correct ABI library.
221
Eric Fiselierb9f425a2015-08-22 19:40:49 +0000222.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
223
224 **Default**: ``OFF``
225
226 Build and use the LLVM unwinder. Note: This option can only be used when
227 libc++abi is the C++ ABI library used.
228
229
230libc++ Feature options
231----------------------
232
233.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
234
235 **Default**: ``ON``
236
237 Build libc++ with exception support.
238
239.. option:: LIBCXX_ENABLE_RTTI:BOOL
240
241 **Default**: ``ON``
242
243 Build libc++ with run time type information.
244
Evgeniy Stepanov4f01aa82015-10-13 23:48:28 +0000245
246libc++ Feature options
247----------------------
248
249The following options allow building libc++ for a different ABI version.
250
251.. option:: LIBCXX_ABI_VERSION:STRING
252
253 **Default**: ``1``
254
255 Defines the target ABI version of libc++.
256
257.. option:: LIBCXX_ABI_UNSTABLE:BOOL
258
259 **Default**: ``OFF``
260
261 Build the "unstable" ABI version of libc++. Includes all ABI changing features
262 on top of the current stable version.
263
Eric Fiselierb9f425a2015-08-22 19:40:49 +0000264.. _LLVM-specific variables:
265
266LLVM-specific options
267---------------------
268
269.. option:: LLVM_LIBDIR_SUFFIX:STRING
270
271 Extra suffix to append to the directory where libraries are to be
272 installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
273 to install libraries to ``/usr/lib64``.
274
275.. option:: LLVM_BUILD_32_BITS:BOOL
276
277 Build 32-bits executables and libraries on 64-bits systems. This option is
278 available only on some 64-bits unix systems. Defaults to OFF.
279
280.. option:: LLVM_LIT_ARGS:STRING
281
282 Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
283 By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
284 others.
285
286
287Using Alternate ABI libraries
288=============================
289
290
291.. _libsupcxx:
292
293Using libsupc++ on Linux
294------------------------
295
296You will need libstdc++ in order to provide libsupc++.
297
298Figure out where the libsupc++ headers are on your system. On Ubuntu this
299is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>``
300
301You can also figure this out by running
302
303.. code-block:: bash
304
305 $ echo | g++ -Wp,-v -x c++ - -fsyntax-only
306 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
307 ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
308 #include "..." search starts here:
309 #include &lt;...&gt; search starts here:
310 /usr/include/c++/4.7
311 /usr/include/c++/4.7/x86_64-linux-gnu
312 /usr/include/c++/4.7/backward
313 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
314 /usr/local/include
315 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
316 /usr/include/x86_64-linux-gnu
317 /usr/include
318 End of search list.
319
320Note that the first two entries happen to be what we are looking for. This
321may not be correct on other platforms.
322
323We can now run CMake:
324
325.. code-block:: bash
326
327 $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \
328 -DLIBCXX_CXX_ABI=libstdc++ \
329 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" \
330 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
331 <libc++-source-dir>
332
333
334You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++``
335above, which will cause the library to be linked to libsupc++ instead
336of libstdc++, but this is only recommended if you know that you will
337never need to link against libstdc++ in the same executable as libc++.
338GCC ships libsupc++ separately but only as a static library. If a
339program also needs to link against libstdc++, it will provide its
340own copy of libsupc++ and this can lead to subtle problems.
341
342.. code-block:: bash
343
344 $ make cxx
345 $ make install
346
347You can now run clang with -stdlib=libc++.
Eric Fiselierd2562802016-06-02 02:16:28 +0000348
349
350.. _libcxxrt_ref:
351
352Using libcxxrt on Linux
353------------------------
354
355You will need to keep the source tree of `libcxxrt`_ available
356on your build machine and your copy of the libcxxrt shared library must
357be placed where your linker will find it.
358
359We can now run CMake like:
360
361.. code-block:: bash
362
363 $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \
364 -DLIBCXX_CXX_ABI=libcxxrt \
365 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxrt-sources/src \
366 -DCMAKE_BUILD_TYPE=Release \
367 -DCMAKE_INSTALL_PREFIX=/usr \
368 <libc++-source-directory>
369 $ make cxx
370 $ make install
371
372Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as
373clang is set up to link for libc++ linked to libsupc++. To get around this
374you'll have to set up your linker yourself (or patch clang). For example,
375
376.. code-block:: bash
377
378 $ clang++ -stdlib=libc++ helloworld.cpp \
379 -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc
380
381Alternately, you could just add libcxxrt to your libraries list, which in most
382situations will give the same result:
383
384.. code-block:: bash
385
386 $ clang++ -stdlib=libc++ helloworld.cpp -lcxxrt
387
388.. _`libcxxrt`: https://github.com/pathscale/libcxxrt/
389
390
391Using a local ABI library installation
392---------------------------------------
393
394.. warning::
395 This is not recommended in almost all cases.
396
397These instructions should only be used when you can't install your ABI library.
398
399Normally you must link libc++ against a ABI shared library that the
400linker can find. If you want to build and test libc++ against an ABI
401library not in the linker's path you needq to set
402``-DLIBCXX_CXX_ABI_LIBRARY_PATH=/path/to/abi/lib`` when configuring CMake.
403
404An example build using libc++abi would look like:
405
406.. code-block:: bash
407
408 $ CC=clang CXX=clang++ cmake \
409 -DLIBCXX_CXX_ABI=libc++abi \
410 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/path/to/libcxxabi/include" \
411 -DLIBCXX_CXX_ABI_LIBRARY_PATH="/path/to/libcxxabi-build/lib" \
412 path/to/libcxx
413 $ make
414
415When testing libc++ LIT will automatically link against the proper ABI
416library.