blob: 821f25d7e04f1e687313a0f4663d8eb3c3784de5 [file] [log] [blame]
Howard Hinnant3e1b0422010-08-22 01:04:38 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
Howard Hinnantc51e1022010-05-11 19:42:16 +00002 "http://www.w3.org/TR/html4/strict.dtd">
3<!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
4<html>
5<head>
6 <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
7 <title>"libc++" C++ Standard Library</title>
8 <link type="text/css" rel="stylesheet" href="menu.css">
9 <link type="text/css" rel="stylesheet" href="content.css">
10</head>
11
12<body>
13<div id="menu">
14 <div>
15 <a href="http://llvm.org/">LLVM Home</a>
16 </div>
Howard Hinnant3e1b0422010-08-22 01:04:38 +000017
Howard Hinnantc51e1022010-05-11 19:42:16 +000018 <div class="submenu">
19 <label>libc++ Info</label>
20 <a href="/index.html">About</a>
21 </div>
22
23 <div class="submenu">
24 <label>Quick Links</label>
Tanya Lattnerd49d4f72015-08-05 03:59:14 +000025 <a href="http://lists.llvm.org/mailman/listinfo/cfe-dev">cfe-dev</a>
26 <a href="http://lists.llvm.org/mailman/listinfo/cfe-commits">cfe-commits</a>
Howard Hinnantc51e1022010-05-11 19:42:16 +000027 <a href="http://llvm.org/bugs/">Bug Reports</a>
Howard Hinnant00171852010-05-11 20:51:20 +000028 <a href="http://llvm.org/svn/llvm-project/libcxx/trunk/">Browse SVN</a>
29 <a href="http://llvm.org/viewvc/llvm-project/libcxx/trunk/">Browse ViewVC</a>
Howard Hinnantc51e1022010-05-11 19:42:16 +000030 </div>
31</div>
32
33<div id="content">
34 <!--*********************************************************************-->
35 <h1>"libc++" C++ Standard Library</h1>
36 <!--*********************************************************************-->
Howard Hinnant3e1b0422010-08-22 01:04:38 +000037
Howard Hinnantc51e1022010-05-11 19:42:16 +000038 <p>libc++ is a new implementation of the C++ standard library, targeting
Howard Hinnantd04724c2012-07-19 15:57:51 +000039 C++11.</p>
Howard Hinnantc51e1022010-05-11 19:42:16 +000040
Chris Lattner7b2aacc2010-11-16 21:40:19 +000041 <p>All of the code in libc++ is <a
42 href="http://llvm.org/docs/DeveloperPolicy.html#license">dual licensed</a>
43 under the MIT license and the UIUC License (a BSD-like license).</p>
Howard Hinnant3e1b0422010-08-22 01:04:38 +000044
Howard Hinnantc51e1022010-05-11 19:42:16 +000045 <!--=====================================================================-->
Eric Fiselier35a5b842015-10-14 20:51:33 +000046 <h2>New Documentation Coming Soon!</h2>
47 <!--=====================================================================-->
48
49 <p> Looking for documentation on how to use, build and test libc++? If so
50 checkout the new libc++ documentation.</p>
51
52 <p><a href="http://libcxx.llvm.org/docs/">
53 Click here for the new libc++ documentation.</a></p>
54
55 <!--=====================================================================-->
Howard Hinnantc51e1022010-05-11 19:42:16 +000056 <h2 id="goals">Features and Goals</h2>
57 <!--=====================================================================-->
Howard Hinnant3e1b0422010-08-22 01:04:38 +000058
Howard Hinnantc51e1022010-05-11 19:42:16 +000059 <ul>
Howard Hinnantd04724c2012-07-19 15:57:51 +000060 <li>Correctness as defined by the C++11 standard.</li>
Howard Hinnantc51e1022010-05-11 19:42:16 +000061 <li>Fast execution.</li>
62 <li>Minimal memory use.</li>
63 <li>Fast compile times.</li>
64 <li>ABI compatibility with gcc's libstdc++ for some low-level features
65 such as exception objects, rtti and memory allocation.</li>
66 <li>Extensive unit tests.</li>
67 </ul>
68
69 <!--=====================================================================-->
Marshall Clowb6a04fe2012-11-14 16:31:15 +000070 <h2 id="why">Why a new C++ Standard Library for C++11?</h2>
Chris Lattnere2b07272010-05-12 22:21:15 +000071 <!--=====================================================================-->
Howard Hinnant3e1b0422010-08-22 01:04:38 +000072
Chris Lattnere2b07272010-05-12 22:21:15 +000073 <p>After its initial introduction, many people have asked "why start a new
74 library instead of contributing to an existing library?" (like Apache's
75 libstdcxx, GNU's libstdc++, STLport, etc). There are many contributing
76 reasons, but some of the major ones are:</p>
Howard Hinnant3e1b0422010-08-22 01:04:38 +000077
Chris Lattnere2b07272010-05-12 22:21:15 +000078 <ul>
79 <li><p>From years of experience (including having implemented the standard
80 library before), we've learned many things about implementing
81 the standard containers which require ABI breakage and fundamental changes
82 to how they are implemented. For example, it is generally accepted that
83 building std::string using the "short string optimization" instead of
84 using Copy On Write (COW) is a superior approach for multicore
Marshall Clowb6a04fe2012-11-14 16:31:15 +000085 machines (particularly in C++11, which has rvalue references). Breaking
Chris Lattnerc67061b2010-05-12 22:30:22 +000086 ABI compatibility with old versions of the library was
Chris Lattnere2b07272010-05-12 22:21:15 +000087 determined to be critical to achieving the performance goals of
88 libc++.</p></li>
Howard Hinnant3e1b0422010-08-22 01:04:38 +000089
Chris Lattnere2b07272010-05-12 22:21:15 +000090 <li><p>Mainline libstdc++ has switched to GPL3, a license which the developers
91 of libc++ cannot use. libstdc++ 4.2 (the last GPL2 version) could be
Marshall Clowb6a04fe2012-11-14 16:31:15 +000092 independently extended to support C++11, but this would be a fork of the
Chris Lattnere7bdfe62010-05-12 22:33:00 +000093 codebase (which is often seen as worse for a project than starting a new
94 independent one). Another problem with libstdc++ is that it is tightly
95 integrated with G++ development, tending to be tied fairly closely to the
96 matching version of G++.</p>
Chris Lattnere2b07272010-05-12 22:21:15 +000097 </li>
98
99 <li><p>STLport and the Apache libstdcxx library are two other popular
Marshall Clowb6a04fe2012-11-14 16:31:15 +0000100 candidates, but both lack C++11 support. Our experience (and the
Howard Hinnantd04724c2012-07-19 15:57:51 +0000101 experience of libstdc++ developers) is that adding support for C++11 (in
Chris Lattnere2b07272010-05-12 22:21:15 +0000102 particular rvalue references and move-only types) requires changes to
103 almost every class and function, essentially amounting to a rewrite.
Chris Lattner48035ce2010-05-12 22:34:21 +0000104 Faced with a rewrite, we decided to start from scratch and evaluate every
105 design decision from first principles based on experience.</p>
Howard Hinnant3e1b0422010-08-22 01:04:38 +0000106
Chris Lattnere2b07272010-05-12 22:21:15 +0000107 <p>Further, both projects are apparently abandoned: STLport 5.2.1 was
108 released in Oct'08, and STDCXX 4.2.1 in May'08.</p>
109
110 </ul>
111
112 <!--=====================================================================-->
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113 <h2 id="requirements">Platform Support</h2>
114 <!--=====================================================================-->
115
Dan Albertce369362014-08-11 15:12:46 +0000116 <p>
117 libc++ is known to work on the following platforms, using g++-4.2 and
118 clang (lack of C++11 language support disables some functionality). Note
119 that functionality provided by &lt;atomic&gt; is only functional with
120 clang.
121 </p>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000122
Dan Albertce369362014-08-11 15:12:46 +0000123 <ul>
124 <li>Mac OS X i386</li>
125 <li>Mac OS X x86_64</li>
126 <li>FreeBSD 10+ i386</li>
127 <li>FreeBSD 10+ x86_64</li>
128 <li>FreeBSD 10+ ARM</li>
129 </ul>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130
131 <!--=====================================================================-->
132 <h2 id="dir-structure">Current Status</h2>
133 <!--=====================================================================-->
134
Howard Hinnant09ce6822012-11-27 18:52:32 +0000135 <p>libc++ is a 100% complete C++11 implementation on Apple's OS X. </p>
Michael J. Spencera86f97e2012-12-31 19:34:21 +0000136 <p>LLVM and Clang can self host in C++ and C++11 mode with libc++ on Linux.</p>
Dan Albert66ddf1f2015-01-30 22:33:41 +0000137 <p>libc++ is also a 100% complete C++14 implementation. A list of new features and changes for
Marshall Clow6d44d712014-04-03 02:35:29 +0000138 C++14 can be found <a href="cxx1y_status.html">here</a>.</p>
Marshall Clow5ac35df2014-11-10 15:43:20 +0000139 <p>A list of features and changes for the next C++ standard, known here as
140 "C++1z" (probably to be C++17) can be found <a href="cxx1z_status.html">here</a>.</p>
Marshall Clowbbec82d2014-06-02 23:37:13 +0000141 <p>Implementation of the post-c++14 Technical Specifications is in progress. A list of features and
142 the current status of these features can be found <a href="ts1z_status.html">here</a>.</p>
Howard Hinnant2347d2f2011-09-28 15:44:39 +0000143 <p>
Howard Hinnante1a0abb2012-07-31 21:30:28 +0000144 Ports to other platforms are underway. Here are recent test
145 results for <a href="results.Windows.html">Windows</a>
146 and <a href="results.Linux.html">Linux</a>.
Howard Hinnant2347d2f2011-09-28 15:44:39 +0000147 </p>
148
Eric Fiselierdc770102014-08-18 05:25:04 +0000149 <!--======================================================================-->
Dan Albert66ddf1f2015-01-30 22:33:41 +0000150 <h2 id="buildbots">Build Bots</h2>
Eric Fiselierdc770102014-08-18 05:25:04 +0000151 <!--======================================================================-->
Eric Fiselierf4e7fc22014-12-09 22:53:21 +0000152 <p>The latest libc++ build results can be found at the following locations.</p>
Eric Fiselierdc770102014-08-18 05:25:04 +0000153 <ul>
Eric Fiselierf4e7fc22014-12-09 22:53:21 +0000154 <li><a href="http://lab.llvm.org:8011/console">
155 Buildbot libc++ builders
Eric Fiselierdc770102014-08-18 05:25:04 +0000156 </a></li>
Eric Fiselierf4e7fc22014-12-09 22:53:21 +0000157 <li><a href="http://lab.llvm.org:8080/green/view/Libcxx/">
158 Jenkins libc++ builders
Eric Fiselier7b7ef162014-10-16 02:48:59 +0000159 </a></li>
Eric Fiselierdc770102014-08-18 05:25:04 +0000160 </ul>
161
Howard Hinnantc51e1022010-05-11 19:42:16 +0000162 <!--=====================================================================-->
163 <h2>Get it and get involved!</h2>
164 <!--=====================================================================-->
Howard Hinnant3e1b0422010-08-22 01:04:38 +0000165
Howard Hinnantf0721aa2011-09-30 16:58:02 +0000166 <p>First please review our
167 <a href="http://llvm.org/docs/DeveloperPolicy.html">Developer's Policy</a>.
168
Howard Hinnantbec2fd52011-11-17 17:14:16 +0000169 <p>
Howard Hinnant79d6bcc2012-11-06 21:31:37 +0000170 On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install
Howard Hinnantbec2fd52011-11-17 17:14:16 +0000171 Xcode 4.2 or later. However if you want to install tip-of-trunk from here
Howard Hinnant961a7352012-04-03 15:08:42 +0000172 (getting the bleeding edge), read on. However, be warned that Mac OS
173 10.7 will not boot without a valid copy of <code>libc++.1.dylib</code> in
174 <code>/usr/lib</code>.
Howard Hinnantbec2fd52011-11-17 17:14:16 +0000175 </p>
176
Dan Albertce369362014-08-11 15:12:46 +0000177 <p>To check out the code, use:</p>
178
Howard Hinnantefc7aa22011-01-27 23:18:19 +0000179 <ul>
Dan Albertce369362014-08-11 15:12:46 +0000180 <li><code>svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx</code></li>
Howard Hinnantefc7aa22011-01-27 23:18:19 +0000181 </ul>
Dan Albertce369362014-08-11 15:12:46 +0000182
Howard Hinnantefc7aa22011-01-27 23:18:19 +0000183 <p>
Dan Albertce369362014-08-11 15:12:46 +0000184 Note that for an in-tree build, you should check out libcxx to
185 llvm/projects.
Howard Hinnantefc7aa22011-01-27 23:18:19 +0000186 </p>
187
Howard Hinnantefc7aa22011-01-27 23:18:19 +0000188 <p>
Dan Albertce369362014-08-11 15:12:46 +0000189 The following instructions are for building libc++ on FreeBSD, Linux, or Mac
190 using <a href="http://libcxxabi.llvm.org/">libc++abi</a> as the C++ ABI
191 library. On Linux, it is also possible to use
192 <a href="#libsupcxx">libsupc++</a> or <a href="#libcxxrt">libcxxrt</a>.
193 </p>
194
195 <p>In-tree build:</p>
196 <ul>
Eric Fiselier156a46d2015-07-30 22:30:34 +0000197 <li><code>cd where-you-want-to-live</code></li>
Dan Albertce369362014-08-11 15:12:46 +0000198 <li>Check out libcxx and <a href="http://libcxxabi.llvm.org/">libcxxabi</a>
199 into llvm/projects</li>
Eric Fiselier156a46d2015-07-30 22:30:34 +0000200 <li><code>cd where-you-want-to-build</code></li>
Dan Albertce369362014-08-11 15:12:46 +0000201 <li><code>mkdir build &amp;&amp; cd build</code></li>
Eric Fiselier156a46d2015-07-30 22:30:34 +0000202 <li><code>cmake path/to/llvm # Linux may require -DCMAKE_C_COMPILER=clang
Dan Albertce369362014-08-11 15:12:46 +0000203 -DCMAKE_CXX_COMPILER=clang++</code></li>
204 <li><code>make cxx</code></li>
205 </ul>
206
Eric Fiselier156a46d2015-07-30 22:30:34 +0000207 <p>Out-of-tree buildc:</p>
Dan Albertce369362014-08-11 15:12:46 +0000208 <ul>
Eric Fiselier156a46d2015-07-30 22:30:34 +0000209 <li><code>cd where-you-want-to-live</code></li>
210 <li>Check out libcxx and llvm</li>
Dan Albertce369362014-08-11 15:12:46 +0000211 <li>If not on a Mac, also check out
212 <a href="http://libcxxabi.llvm.org/">libcxxabi</a></li>
Eric Fiselier156a46d2015-07-30 22:30:34 +0000213 <li><code>cd where-you-want-to-build</code></li>
Dan Albertce369362014-08-11 15:12:46 +0000214 <li><code>mkdir build &amp;&amp; cd build</code></li>
Eric Fiselier156a46d2015-07-30 22:30:34 +0000215 <li><code>cmake -DLLVM_PATH=path/to/llvm
216 -DLIBCXX_CXX_ABI=libcxxabi
Eric Fiselier828d6c42015-03-19 20:59:45 +0000217 -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxabi/include
Eric Fiselier156a46d2015-07-30 22:30:34 +0000218 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
219 path/to/libcxx
220 </code></li>
Dan Albertce369362014-08-11 15:12:46 +0000221 <li><code>make</code></li>
222 </ul>
223
224 <p>To run the tests:</p>
225 <ul>
226 <li><code>make check-libcxx</code></li>
227 </ul>
228
229 <p>If you wish to run a subset of the test suite:</p>
230 <ul>
231 <li><code>cd path/to/libcxx/libcxx</code></li>
232 <li><code>alias lit='python path/to/llvm/utils/lit/lit.py'</code></li>
Eric Fiselier26dcc932014-12-20 03:16:55 +0000233 <li><code>export
234 LIBCXX_SITE_CONFIG=path/to/build/dir/projects/libcxx/test/lit.site.cfg
235 </code></li>
Dan Albertce369362014-08-11 15:12:46 +0000236 <li><code>lit -sv test/re/ # or whichever subset of tests you're interested
237 in</code></li>
238 </ul>
239 <p>The above is currently quite inconvenient. Sorry! We're working on it!</p>
240
241 <p>More information on using LIT can be found
242 <a href="http://llvm.org/docs/CommandGuide/lit.html">here</a>. For more
243 general information about the LLVM testing infrastructure, see the
244 <a href="http://llvm.org/docs/TestingGuide.html">LLVM Testing Infrastructure
245 Guide</a>
246 </p>
247
248 <p>
249 Shared libraries for libc++ should now be present in llvm/build/lib. Note
250 that it is safest to use this from its current location rather than
251 replacing your system's libc++ (if it has one, if not, go right ahead).
252 </p>
253
254 <p>
255 Mac users, remember to be careful when replacing the system's libc++.
Jonathan Roelofsc52d50a2015-05-08 21:11:49 +0000256 <strong>Your system will not be able to boot without a functioning
Dan Albertce369362014-08-11 15:12:46 +0000257 libc++.</strong>
258 </p>
259
260 <!--=====================================================================-->
Eric Fiselier24186c72015-05-12 22:55:30 +0000261 <h3>Notes and Known Issues</h3>
Dan Albertce369362014-08-11 15:12:46 +0000262 <!--=====================================================================-->
263
264 <p>
Eric Fiselier24186c72015-05-12 22:55:30 +0000265 <ul>
266 <li>
267 Building libc++ with <code>-fno-rtti</code> is not supported. However
268 linking against it with <code>-fno-rtti</code> is supported.
269 </li>
270 <li>
271 On OS X v10.8 and older the CMake option
272 <code>-DLIBCXX_LIBCPPABI_VERSION=""</code> must be used during
273 configuration.
274 </li>
275 </ul>
Dan Albertce369362014-08-11 15:12:46 +0000276 </p>
277
278 <p>Send discussions to the
Tanya Lattnerd49d4f72015-08-05 03:59:14 +0000279 <a href="http://lists.llvm.org/mailman/listinfo/cfe-dev">clang mailing list</a>.</p>
Dan Albertce369362014-08-11 15:12:46 +0000280
281 <!--=====================================================================-->
282 <h2>Using libc++ in your programs</h2>
283 <!--=====================================================================-->
284
285 <!--=====================================================================-->
286 <h3>FreeBSD and Mac OS X</h3>
287 <!--=====================================================================-->
288
289 <p>
290 To use your system-installed libc++ with clang you can:
Howard Hinnantefc7aa22011-01-27 23:18:19 +0000291 </p>
292
293 <ul>
294 <li><code>clang++ -stdlib=libc++ test.cpp</code></li>
Howard Hinnantd04724c2012-07-19 15:57:51 +0000295 <li><code>clang++ -std=c++11 -stdlib=libc++ test.cpp</code></li>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000296 </ul>
297
Howard Hinnant79d6bcc2012-11-06 21:31:37 +0000298 <p>
Dan Albertce369362014-08-11 15:12:46 +0000299 To use your tip-of-trunk libc++ on Mac OS with clang you can:
Howard Hinnant79d6bcc2012-11-06 21:31:37 +0000300 </p>
301
302 <ul>
Dan Albertce369362014-08-11 15:12:46 +0000303 <li><code>export DYLD_LIBRARY_PATH=path/to/build/lib</code>
Howard Hinnant79d6bcc2012-11-06 21:31:37 +0000304 <li><code>clang++ -std=c++11 -stdlib=libc++ -nostdinc++
305 -I&lt;path-to-libcxx&gt;/include -L&lt;path-to-libcxx&gt;/lib
306 test.cpp</code></li>
307 </ul>
308
Dan Albertce369362014-08-11 15:12:46 +0000309 <!--=====================================================================-->
310 <h3>Linux</h3>
311 <!--=====================================================================-->
312
313 <p>
314 You will need to keep the source tree of
315 <a href="http://libcxxabi.llvm.org">libc++abi</a> available on your build
316 machine and your copy of the libc++abi shared library must be placed where
317 your linker will find it.
318 </p>
319
320 <p>
321 Unfortunately you can't simply run clang with "-stdlib=libc++" at this
322 point, as clang is set up to link for libc++ linked to libsupc++. To get
323 around this you'll have to set up your linker yourself (or patch clang).
324 For example:
325 </p>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000326
327 <ul>
Dan Albertce369362014-08-11 15:12:46 +0000328 <li><code>clang++ -stdlib=libc++ helloworld.cpp -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc</code></li>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000329 </ul>
330
Dan Albertce369362014-08-11 15:12:46 +0000331 <p>
332 Alternately, you could just add libc++abi to your libraries list, which in
333 most situations will give the same result:
334 </p>
Howard Hinnant24147cf2012-05-20 13:03:53 +0000335
Dan Albertce369362014-08-11 15:12:46 +0000336 <ul>
337 <li><code>clang++ -stdlib=libc++ helloworld.cpp -lc++abi</code></li>
338 </ul>
Howard Hinnantc5b02f22010-05-11 19:53:34 +0000339
Howard Hinnantbded6c92010-10-05 16:44:40 +0000340 <!--=====================================================================-->
Marshall Clowf7cc9a12014-04-03 03:13:12 +0000341 <h2>Bug reports and patches</h2>
342 <!--=====================================================================-->
343
Dan Albert66ddf1f2015-01-30 22:33:41 +0000344 <p>
345 If you think you've found a bug in libc++, please report it using
346 the <a href="http://llvm.org/bugs">LLVM Bugzilla</a>. If you're not sure, you
Tanya Lattnerd49d4f72015-08-05 03:59:14 +0000347 can post a message to the <a href="http://lists.llvm.org/mailman/listinfo/cfe-dev">cfe-dev</a>
Dan Albert66ddf1f2015-01-30 22:33:41 +0000348 mailing list or on IRC. Please include "libc++" in your subject.
349 </p>
Marshall Clowf7cc9a12014-04-03 03:13:12 +0000350
Dan Albert66ddf1f2015-01-30 22:33:41 +0000351 <p>
352 If you want to contribute a patch to libc++, the best place for that is
353 <a href="http://llvm.org/docs/Phabricator.html">Phabricator</a>. Please
354 include [libc++] in the subject and add cfe-commits as a subscriber.
355 </p>
Marshall Clowf7cc9a12014-04-03 03:13:12 +0000356
357 <!--=====================================================================-->
Dan Albertce369362014-08-11 15:12:46 +0000358 <h2 id="libsupcxx">Build on Linux using CMake and libsupc++.</h2>
Michael J. Spencera86f97e2012-12-31 19:34:21 +0000359 <!--=====================================================================-->
360
361 <p>
362 You will need libstdc++ in order to provide libsupc++.
363 </p>
Dan Albert66ddf1f2015-01-30 22:33:41 +0000364
Michael J. Spencera86f97e2012-12-31 19:34:21 +0000365 <p>
366 Figure out where the libsupc++ headers are on your system. On Ubuntu this
367 is <code>/usr/include/c++/&lt;version&gt;</code> and
368 <code>/usr/include/c++/&lt;version&gt;/&lt;target-triple&gt;</code>
369 </p>
Dan Albert66ddf1f2015-01-30 22:33:41 +0000370
Michael J. Spencera86f97e2012-12-31 19:34:21 +0000371 <p>
372 You can also figure this out by running
373 <pre>
374$ echo | g++ -Wp,-v -x c++ - -fsyntax-only
375ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
376ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
377#include "..." search starts here:
378#include &lt;...&gt; search starts here:
379 /usr/include/c++/4.7
380 /usr/include/c++/4.7/x86_64-linux-gnu
381 /usr/include/c++/4.7/backward
382 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
383 /usr/local/include
384 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
385 /usr/include/x86_64-linux-gnu
386 /usr/include
387End of search list.
388 </pre>
389
390 Note the first two entries happen to be what we are looking for. This
391 may not be correct on other platforms.
392 </p>
Dan Albert66ddf1f2015-01-30 22:33:41 +0000393
Michael J. Spencera86f97e2012-12-31 19:34:21 +0000394 <p>
395 We can now run CMake:
396 <ul>
397 <li><code>CC=clang CXX=clang++ cmake -G "Unix Makefiles"
Peter Collingbourne22dc63b2013-10-06 22:13:19 +0000398 -DLIBCXX_CXX_ABI=libstdc++
Eric Fiselier828d6c42015-03-19 20:59:45 +0000399 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/"
Michael J. Spencera86f97e2012-12-31 19:34:21 +0000400 -DCMAKE_BUILD_TYPE=Release
401 -DCMAKE_INSTALL_PREFIX=/usr
402 &lt;libc++-source-dir&gt;</code></li>
Peter Collingbourne22dc63b2013-10-06 22:13:19 +0000403 <li>You can also substitute <code>-DLIBCXX_CXX_ABI=libsupc++</code>
404 above, which will cause the library to be linked to libsupc++ instead
405 of libstdc++, but this is only recommended if you know that you will
406 never need to link against libstdc++ in the same executable as libc++.
407 GCC ships libsupc++ separately but only as a static library. If a
408 program also needs to link against libstdc++, it will provide its
409 own copy of libsupc++ and this can lead to subtle problems.
Michael J. Spencera86f97e2012-12-31 19:34:21 +0000410 <li><code>make</code></li>
411 <li><code>sudo make install</code></li>
412 </ul>
413 <p>
414 You can now run clang with -stdlib=libc++.
415 </p>
416 </p>
417
418 <!--=====================================================================-->
Dan Albertce369362014-08-11 15:12:46 +0000419 <h2 id="libcxxrt">Build on Linux using CMake and libcxxrt.</h2>
Howard Hinnant8d3824d2013-02-08 19:10:36 +0000420 <!--=====================================================================-->
421
422 <p>
423 You will need to keep the source tree of
424 <a href="https://github.com/pathscale/libcxxrt/">libcxxrt</a> available
425 on your build machine and your copy of the libcxxrt shared library must
426 be placed where your linker will find it.
427 </p>
Dan Albert66ddf1f2015-01-30 22:33:41 +0000428
Howard Hinnant8d3824d2013-02-08 19:10:36 +0000429 <p>
430 We can now run CMake:
431 <ul>
432 <li><code>CC=clang CXX=clang++ cmake -G "Unix Makefiles"
433 -DLIBCXX_CXX_ABI=libcxxrt
Eric Fiselier828d6c42015-03-19 20:59:45 +0000434 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="&lt;libcxxrt-source-dir&gt;/src"
Howard Hinnant8d3824d2013-02-08 19:10:36 +0000435 -DCMAKE_BUILD_TYPE=Release
436 -DCMAKE_INSTALL_PREFIX=/usr
437 &lt;libc++-source-dir&gt;</code></li>
438 <li><code>make</code></li>
439 <li><code>sudo make install</code></li>
440 </ul>
441 <p>
442 Unfortunately you can't simply run clang with "-stdlib=libc++" at this point, as
443 clang is set up to link for libc++ linked to libsupc++. To get around this
444 you'll have to set up your linker yourself (or patch clang). For example,
445 <ul>
446 <li><code>clang++ -stdlib=libc++ helloworld.cpp -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc</code></li>
447 </ul>
448 Alternately, you could just add libcxxrt to your libraries list, which in most
449 situations will give the same result:
450 <ul>
451 <li><code>clang++ -stdlib=libc++ helloworld.cpp -lcxxrt</code></li>
452 </ul>
453 </p>
454 </p>
455
456 <!--=====================================================================-->
Eric Fiselierf2348552014-10-18 01:15:17 +0000457 <h2 id="local-abi">Using a local ABI library</h2>
458 <!--=====================================================================-->
459 <p>
460 <strong>Note: This is not recommended in almost all cases.</strong><br>
461 Generally these instructions should only be used when you can't install
462 your ABI library.
463 </p>
464 <p>
465 Normally you must link libc++ against a ABI shared library that the
466 linker can find. If you want to build and test libc++ against an ABI
467 library not in the linker's path you need to set
Eric Fiseliere1b33602014-10-19 00:42:41 +0000468 <code>-DLIBCXX_CXX_ABI_LIBRARY_PATH=/path/to/abi/lib</code> when
469 configuring CMake.
Eric Fiselierf2348552014-10-18 01:15:17 +0000470 </p>
471 <p>
472 An example build using libc++abi would look like:
473 <ul>
474 <li><code>CC=clang CXX=clang++ cmake
475 -DLIBCXX_CXX_ABI=libc++abi
Eric Fiselier828d6c42015-03-19 20:59:45 +0000476 -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/path/to/libcxxabi/include"
Eric Fiseliere1b33602014-10-19 00:42:41 +0000477 -DLIBCXX_CXX_ABI_LIBRARY_PATH="/path/to/libcxxabi-build/lib"
Eric Fiselierf2348552014-10-18 01:15:17 +0000478 path/to/libcxx</code></li>
479 <li><code>make</code></li>
480 </ul>
481 </p>
482 <p>
483 When testing libc++ LIT will automatically link against the proper ABI
484 library.
485 </p>
486
487 <!--=====================================================================-->
Howard Hinnantbded6c92010-10-05 16:44:40 +0000488 <h2>Design Documents</h2>
489 <!--=====================================================================-->
490
491<ul>
492<li><a href="atomic_design.html"><tt>&lt;atomic&gt;</tt></a></li>
Howard Hinnante20b8de2010-11-19 01:38:58 +0000493<li><a href="type_traits_design.html"><tt>&lt;type_traits&gt;</tt></a></li>
Marshall Clow68aa6b42013-03-14 19:00:34 +0000494<li><a href="http://cplusplusmusings.wordpress.com/2012/07/05/clang-and-standard-libraries-on-mac-os-x/">Excellent notes by Marshall Clow</a></li>
Howard Hinnant57724c32013-03-14 18:37:48 +0000495<li><a href="debug_mode.html">Status of debug mode</a></li>
Eric Fiselierab2e73d2014-12-22 20:49:45 +0000496<li><a href="lit_usage.html">LIT usage guide</a></li>
Howard Hinnantbded6c92010-10-05 16:44:40 +0000497</ul>
498
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499</div>
500</body>
Chris Lattnere66f1e32010-05-11 20:37:52 +0000501</html>