BuildingLibcxx.rst 8.8 KB

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