b9f425a434
Summary: This patch adds Sphinx based documentation to libc++. The goal is to make it easier to write documentation for libc++ since writing new documentation in HTML is cumbersome. This patch rewrites the main page for libc++ along with the instructions for using, building and testing libc++. The built documentation can be found and reviewed here: http://efcs.ca/libcxx-docs In order to build the sphinx documentation you need to specify the cmake options `-DLLVM_ENABLE_SPHINX=ON -DLIBCXX_INCLUDE_DOCS=ON`. This will add the makefile rule `docs-libcxx-html`. Reviewers: chandlerc, mclow.lists, danalbert, jroelofs Subscribers: silvas, cfe-commits Differential Revision: http://reviews.llvm.org/D12129 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@245788 91177308-0d34-0410-b5e6-96231b3b80d8
90 lines
2.7 KiB
ReStructuredText
90 lines
2.7 KiB
ReStructuredText
============
|
|
Using libc++
|
|
============
|
|
|
|
.. contents::
|
|
:local:
|
|
|
|
Getting Started
|
|
===============
|
|
|
|
If you already have libc++ installed you can use it with clang.
|
|
|
|
.. code-block:: bash
|
|
|
|
$ clang++ -stdlib=libc++ test.cpp
|
|
$ clang++ -std=c++11 -stdlib=libc++ test.cpp
|
|
|
|
On OS X and FreeBSD libc++ is the default standard library
|
|
and the ``-stdlib=libc++`` is not required.
|
|
|
|
.. _alternate libcxx:
|
|
|
|
If you want to select an alternate installation of libc++ you
|
|
can use the following options.
|
|
|
|
.. code-block:: bash
|
|
|
|
$ clang++ -std=c++11 -stdlib=libc++ -nostdinc++ \
|
|
-I<libcxx-install-prefix>/include/c++/v1 \
|
|
-L<libcxx-install-prefix>/lib \
|
|
-Wl,-rpath,<libcxx-install-prefix>/lib \
|
|
test.cpp
|
|
|
|
The option ``-Wl,-rpath,<libcxx-install-prefix>/lib`` adds a runtime library
|
|
search path. Meaning that the systems dynamic linker will look for libc++ in
|
|
``<libcxx-install-prefix>/lib`` whenever the program is run. Alternatively the
|
|
environment variable ``LD_LIBRARY_PATH`` (``DYLD_LIBRARY_PATH`` on OS X) can
|
|
be used to change the dynamic linkers search paths after a program is compiled.
|
|
|
|
An example of using ``LD_LIBRARY_PATH``:
|
|
|
|
.. code-block:: bash
|
|
|
|
$ clang++ -stdlib=libc++ -nostdinc++ \
|
|
-I<libcxx-install-prefix>/include/c++/v1
|
|
-L<libcxx-install-prefix>/lib \
|
|
test.cpp -o
|
|
$ ./a.out # Searches for libc++ in the systems library paths.
|
|
$ export LD_LIBRARY_PATH=<libcxx-install-prefix>/lib
|
|
$ ./a.out # Searches for libc++ along LD_LIBRARY_PATH
|
|
|
|
|
|
|
|
Using libc++ on Linux
|
|
=====================
|
|
|
|
On Linux libc++ typically links to a shared version of libc++abi. Unfortunately
|
|
you can't simply run clang with "-stdlib=libc++" as clang is not set up to
|
|
link for this configuration. To get around this you'll have to manually
|
|
link libc++abi yourself. For example:
|
|
|
|
.. code-block:: bash
|
|
|
|
$ clang++ -stdlib=libc++ test.cpp -lc++ -lc++abi -lm -lc -lgcc_s -lgcc
|
|
|
|
Alternately, you could just add libc++abi to your libraries list, which in
|
|
most situations will give the same result:
|
|
|
|
.. code-block:: bash
|
|
|
|
$ clang++ -stdlib=libc++ test.cpp -lc++abi
|
|
|
|
|
|
Using libc++ with GCC
|
|
---------------------
|
|
|
|
GCC does not provide a way to switch from libstdc++ to libc++. You must manually
|
|
configure the compile and link commands.
|
|
|
|
In particular you must tell GCC to remove the libstdc++ include directories
|
|
using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``.
|
|
|
|
Note that ``-nodefaultlibs`` removes all of the standard system libraries and
|
|
not just libstdc++ so they must be manually linked. For example:
|
|
|
|
.. code-block:: bash
|
|
|
|
$ g++ -nostdinc++ -I<libcxx-install-prefix>/include/c++/v1 \
|
|
test.cpp -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc
|