blob: aa3a385cbde88df443474e7ffdf0d6641a2fbedd [file] [log] [blame]
Eric Fiselierd720d1f2015-08-22 19:40:49 +00001
2===============
3Building libc++
4===============
5
6.. contents::
7 :local:
8
9Getting Started
10===============
11
12On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install
13Xcode 4.2 or later. However if you want to install tip-of-trunk from here
14(getting the bleeding edge), read on.
15
16The basic steps needed to build libc++ are:
17
18#. Checkout LLVM:
19
20 * ``cd where-you-want-llvm-to-live``
21 * ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
22
23#. Checkout libc++:
24
25 * ``cd where-you-want-llvm-to-live``
26 * ``cd llvm/tools``
27 * ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx``
28
29#. Checkout libc++abi:
30
31 * ``cd where-you-want-llvm-to-live``
32 * ``cd llvm/projects``
33 * ``svn co http://llvm.org/svn/llvm-project/libc++abi libc++abi``
34
35#. Configure and build libc++ with libc++abi:
36
37 `CMake <CMake.html>`_ is the only supported configuration system. Unlike other LLVM
38 projects autotools is not supported for either libc++ or libc++abi.
39
40 Clang is the preferred compiler when building and using libc++.
41
42 * ``cd where you want to build llvm``
43 * ``mkdir build``
44 * ``cd build``
45 * ``cmake -G <generator> [options] <path to llvm sources>``
46
47 For more information about configuring libc++ see :ref:`CMake Options`.
48
49 * ``make cxx`` --- will build libc++ and libc++abi.
50 * ``make check-libcxx check-libcxxabi`` --- will run the test suites.
51
52 Shared libraries for libc++ and libc++ abi should now be present in llvm/build/lib.
53 See :ref:`using an alternate libc++ installation <alternate libcxx>`
54
55#. **Optional**: Install libc++ and libc++abi
56
57 If your system already provides a libc++ installation it is important to be
58 careful not to replace it. Remember Use the CMake option ``CMAKE_INSTALL_PREFIX`` to
59 select a safe place to install libc++.
60
61 * ``make install-libcxx install-libcxxabi`` --- Will install the libraries and the headers
62
63 .. warning::
64 * Replacing your systems libc++ installation could render the system non-functional.
65 * Mac OS X will not boot without a valid copy of ``libc++.1.dylib`` in ``/usr/lib``.
66
67
68The instructions are for building libc++ on
69FreeBSD, Linux, or Mac using `libc++abi`_ as the C++ ABI library.
70On Linux, it is also possible to use :ref:`libsupc++ <libsupcxx>` or libcxxrt.
71
72It is sometimes beneficial to build outside of the LLVM tree. To build
73libc++ TODO
74
75.. code-block:: bash
76
77 $ cd where-you-want-libcxx-to-live
78 $ # Check out llvm, libc++ and libc++abi.
79 $ ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm``
80 $ ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx``
81 $ ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi``
82 $ cd where-you-want-to-build
83 $ mkdir build && cd build
84 $ export CC=clang CXX=clang++
85 $ cmake -DLLVM_PATH=path/to/llvm \
86 -DLIBCXX_CXX_ABI=libcxxabi \
87 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxabi/include \
88 path/to/libcxx
89 $ make
90 $ make check-libcxx # optional
91
92
93.. _`libc++abi`: http://libcxxabi.llvm.org/
94
95
96.. _CMake Options:
97
98CMake Options
99=============
100
101Here are some of the CMake variables that are used often, along with a
102brief explanation and LLVM-specific notes. For full documentation, check the
103CMake docs or execute ``cmake --help-variable VARIABLE_NAME``.
104
105**CMAKE_BUILD_TYPE**:STRING
106 Sets the build type for ``make`` based generators. Possible values are
107 Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio
108 the user sets the build type with the IDE settings.
109
110**CMAKE_INSTALL_PREFIX**:PATH
111 Path where LLVM will be installed if "make install" is invoked or the
112 "INSTALL" target is built.
113
114**CMAKE_CXX_COMPILER**:STRING
115 The C++ compiler to use when building and testing libc++.
116
117
118.. _libcxx-specific options:
119
120libc++ specific options
121-----------------------
122
123.. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL
124
125 **Default**: ``ON``
126
127 Build libc++ with assertions enabled.
128
129.. option:: LIBCXX_BUILD_32_BITS:BOOL
130
131 **Default**: ``OFF``
132
133 Build libc++ as a 32 bit library. Also see :option:`LLVM_BUILD_32_BITS`.
134
135.. option:: LIBCXX_ENABLE_SHARED:BOOL
136
137 **Default**: ``ON``
138
139 Build libc++ as a shared library. If ``OFF`` is specified then libc++ is
140 built as a static library.
141
142.. option:: LIBCXX_LIBDIR_SUFFIX:STRING
143
144 Extra suffix to append to the directory where libraries are to be installed.
145 This option overrides :option:`LLVM_LIBDIR_SUFFIX`.
146
147.. _ABI Library Specific Options:
148
149ABI Library Specific Options
150----------------------------
151
152.. option:: LIBCXX_CXX_ABI:STRING
153
154 **Values**: ``none``, ``libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``.
155
156 Select the ABI library to build libc++ against.
157
158.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS
159
160 Provide additional search paths for the ABI library headers.
161
162.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH
163
164 Provide the path to the ABI library that libc++ should link against.
165
166.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL
167
168 **Default**: ``OFF``
169
170 If this option is enabled, libc++ will try and link the selected ABI library
171 statically.
172
173.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL
174
175 **Default**: ``OFF``
176
177 Build and use the LLVM unwinder. Note: This option can only be used when
178 libc++abi is the C++ ABI library used.
179
180
181libc++ Feature options
182----------------------
183
184.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL
185
186 **Default**: ``ON``
187
188 Build libc++ with exception support.
189
190.. option:: LIBCXX_ENABLE_RTTI:BOOL
191
192 **Default**: ``ON``
193
194 Build libc++ with run time type information.
195
196.. _LLVM-specific variables:
197
198LLVM-specific options
199---------------------
200
201.. option:: LLVM_LIBDIR_SUFFIX:STRING
202
203 Extra suffix to append to the directory where libraries are to be
204 installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64``
205 to install libraries to ``/usr/lib64``.
206
207.. option:: LLVM_BUILD_32_BITS:BOOL
208
209 Build 32-bits executables and libraries on 64-bits systems. This option is
210 available only on some 64-bits unix systems. Defaults to OFF.
211
212.. option:: LLVM_LIT_ARGS:STRING
213
214 Arguments given to lit. ``make check`` and ``make clang-test`` are affected.
215 By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on
216 others.
217
218
219Using Alternate ABI libraries
220=============================
221
222
223.. _libsupcxx:
224
225Using libsupc++ on Linux
226------------------------
227
228You will need libstdc++ in order to provide libsupc++.
229
230Figure out where the libsupc++ headers are on your system. On Ubuntu this
231is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>``
232
233You can also figure this out by running
234
235.. code-block:: bash
236
237 $ echo | g++ -Wp,-v -x c++ - -fsyntax-only
238 ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
239 ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
240 #include "..." search starts here:
241 #include &lt;...&gt; search starts here:
242 /usr/include/c++/4.7
243 /usr/include/c++/4.7/x86_64-linux-gnu
244 /usr/include/c++/4.7/backward
245 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
246 /usr/local/include
247 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
248 /usr/include/x86_64-linux-gnu
249 /usr/include
250 End of search list.
251
252Note that the first two entries happen to be what we are looking for. This
253may not be correct on other platforms.
254
255We can now run CMake:
256
257.. code-block:: bash
258
259 $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \
260 -DLIBCXX_CXX_ABI=libstdc++ \
261 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" \
262 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \
263 <libc++-source-dir>
264
265
266You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++``
267above, which will cause the library to be linked to libsupc++ instead
268of libstdc++, but this is only recommended if you know that you will
269never need to link against libstdc++ in the same executable as libc++.
270GCC ships libsupc++ separately but only as a static library. If a
271program also needs to link against libstdc++, it will provide its
272own copy of libsupc++ and this can lead to subtle problems.
273
274.. code-block:: bash
275
276 $ make cxx
277 $ make install
278
279You can now run clang with -stdlib=libc++.