1
- .. _ using-libcxx :
1
+ .. _ user-documentation :
2
2
3
- ============
4
- Using libc++
5
- ============
3
+ ==================
4
+ User documentation
5
+ ==================
6
6
7
7
.. contents ::
8
8
:local:
9
9
10
- Usually, libc++ is packaged and shipped by a vendor through some delivery vehicle
11
- (operating system distribution, SDK, toolchain, etc) and users don't need to do
12
- anything special in order to use the library.
13
-
14
10
This page contains information about configuration knobs that can be used by
15
11
users when they know libc++ is used by their toolchain, and how to use libc++
16
- when it is not the default library used by their toolchain.
12
+ when it is not the default library used by their toolchain. It is aimed at
13
+ users of libc++: a separate page contains documentation aimed at vendors who
14
+ build and ship libc++ as part of their toolchain.
17
15
18
16
19
17
Using a different version of the C++ Standard
@@ -28,10 +26,29 @@ matches that Standard in the library.
28
26
29
27
$ clang++ -std=c++17 test.cpp
30
28
31
- .. warning ::
32
- Using ``-std=c++XY `` with a version of the Standard that has not been ratified yet
33
- is considered unstable. Libc++ reserves the right to make breaking changes to the
34
- library until the standard has been ratified.
29
+ Note that using ``-std=c++XY `` with a version of the Standard that has not been ratified
30
+ yet is considered unstable. While we strive to maintain stability, libc++ may be forced to
31
+ make breaking changes to features shipped in a Standard that hasn't been ratified yet. Use
32
+ these versions of the Standard at your own risk.
33
+
34
+
35
+ Using libc++ when it is not the system default
36
+ ==============================================
37
+
38
+ Usually, libc++ is packaged and shipped by a vendor through some delivery vehicle
39
+ (operating system distribution, SDK, toolchain, etc) and users don't need to do
40
+ anything special in order to use the library.
41
+
42
+ On systems where libc++ is provided but is not the default, Clang provides a flag
43
+ called ``-stdlib= `` that can be used to decide which standard library is used.
44
+ Using ``-stdlib=libc++ `` will select libc++:
45
+
46
+ .. code-block :: bash
47
+
48
+ $ clang++ -stdlib=libc++ test.cpp
49
+
50
+ On systems where libc++ is the library in use by default such as macOS and FreeBSD,
51
+ this flag is not required.
35
52
36
53
37
54
Enabling experimental C++ Library features
@@ -43,6 +60,11 @@ the Standard but whose implementation is not complete or stable yet in libc++. T
43
60
are disabled by default because they are neither API nor ABI stable. However, the
44
61
``-fexperimental-library `` compiler flag can be defined to turn those features on.
45
62
63
+ On compilers that do not support the ``-fexperimental-library `` flag (such as GCC),
64
+ users can define the ``_LIBCPP_ENABLE_EXPERIMENTAL `` macro and manually link against
65
+ the appropriate static library (usually shipped as ``libc++experimental.a ``) to get
66
+ access to experimental library features.
67
+
46
68
The following features are currently considered experimental and are only provided
47
69
when ``-fexperimental-library `` is passed:
48
70
@@ -51,7 +73,7 @@ when ``-fexperimental-library`` is passed:
51
73
* ``std::jthread ``
52
74
* ``std::chrono::tzdb `` and related time zone functionality
53
75
54
- .. warning ::
76
+ .. note ::
55
77
Experimental libraries are experimental.
56
78
* The contents of the ``<experimental/...> `` headers and the associated static
57
79
library will not remain compatible between versions.
@@ -60,98 +82,18 @@ when ``-fexperimental-library`` is passed:
60
82
the experimental feature is removed two releases after the non-experimental
61
83
version has shipped. The full policy is explained :ref: `here <experimental features >`.
62
84
63
- .. note ::
64
- On compilers that do not support the ``-fexperimental-library `` flag, users can
65
- define the ``_LIBCPP_ENABLE_EXPERIMENTAL `` macro and manually link against the
66
- appropriate static library (usually shipped as ``libc++experimental.a ``) to get
67
- access to experimental library features.
68
-
69
-
70
- Using libc++ when it is not the system default
71
- ==============================================
72
-
73
- On systems where libc++ is provided but is not the default, Clang provides a flag
74
- called ``-stdlib= `` that can be used to decide which standard library is used.
75
- Using ``-stdlib=libc++ `` will select libc++:
76
-
77
- .. code-block :: bash
78
-
79
- $ clang++ -stdlib=libc++ test.cpp
80
-
81
- On systems where libc++ is the library in use by default such as macOS and FreeBSD,
82
- this flag is not required.
83
-
84
-
85
- .. _alternate libcxx :
86
-
87
- Using a custom built libc++
88
- ===========================
89
-
90
- Most compilers provide a way to disable the default behavior for finding the
91
- standard library and to override it with custom paths. With Clang, this can
92
- be done with:
93
-
94
- .. code-block :: bash
95
-
96
- $ clang++ -nostdinc++ -nostdlib++ \
97
- -isystem < install> /include/c++/v1 \
98
- -L < install> /lib \
99
- -Wl,-rpath,< install> /lib \
100
- -lc++ \
101
- test.cpp
102
-
103
- The option ``-Wl,-rpath,<install>/lib `` adds a runtime library search path,
104
- which causes the system's dynamic linker to look for libc++ in ``<install>/lib ``
105
- whenever the program is loaded.
106
-
107
- GCC does not support the ``-nostdlib++ `` flag, so one must use ``-nodefaultlibs ``
108
- instead. Since that removes all the standard system libraries and not just libc++,
109
- the system libraries must be re-added manually. For example:
110
-
111
- .. code-block :: bash
112
-
113
- $ g++ -nostdinc++ -nodefaultlibs \
114
- -isystem < install> /include/c++/v1 \
115
- -L < install> /lib \
116
- -Wl,-rpath,< install> /lib \
117
- -lc++ -lc++abi -lm -lc -lgcc_s -lgcc \
118
- test.cpp
119
-
120
-
121
- GDB Pretty printers for libc++
122
- ==============================
123
-
124
- GDB does not support pretty-printing of libc++ symbols by default. However, libc++ does
125
- provide pretty-printers itself. Those can be used as:
126
-
127
- .. code-block :: bash
128
-
129
- $ gdb -ex " source <libcxx>/utils/gdb/libcxx/printers.py" \
130
- -ex " python register_libcxx_printer_loader()" \
131
- < args>
132
-
133
- .. _include-what-you-use :
134
-
135
- include-what-you-use (IWYU)
136
- ===========================
137
-
138
- libc++ provides an IWYU `mapping file <https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md >`_,
139
- which drastically improves the accuracy of the tool when using libc++. To use the mapping file with
140
- IWYU, you should run the tool like so:
141
-
142
- .. code-block :: bash
143
-
144
- $ include-what-you-use -Xiwyu --mapping_file=/path/to/libcxx/include/libcxx.imp file.cpp
145
-
146
- If you would prefer to not use that flag, then you can replace ``/path/to/include-what-you-use/share/libcxx.imp ``
147
- file with the libc++-provided ``libcxx.imp `` file.
148
85
149
86
Libc++ Configuration Macros
150
87
===========================
151
88
152
- Libc++ provides a number of configuration macros which can be used to enable
153
- or disable extended libc++ behavior, including enabling hardening or thread
154
- safety annotations.
89
+ Libc++ provides a number of configuration macros that can be used by developers to
90
+ enable or disable extended libc++ behavior.
91
+
92
+ .. warning ::
93
+ Configuration macros that are not documented here are not intended to be customized
94
+ by developers and should not be used. In particular, some configuration macros are
95
+ only intended to be used by vendors and changing their value from the one provided
96
+ in your toolchain can lead to unexpected behavior.
155
97
156
98
**_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS **:
157
99
This macro is used to enable -Wthread-safety annotations on libc++'s
@@ -193,6 +135,12 @@ safety annotations.
193
135
warning saying that `std::auto_ptr ` is deprecated. If the macro is defined,
194
136
no warning will be emitted. By default, this macro is not defined.
195
137
138
+ **_LIBCPP_ENABLE_EXPERIMENTAL **:
139
+ This macro enables experimental features. This can be used on compilers that do
140
+ not support the ``-fexperimental-library `` flag. When used, users also need to
141
+ ensure that the appropriate experimental library (usually ``libc++experimental.a ``)
142
+ is linked into their program.
143
+
196
144
C++17 Specific Configuration Macros
197
145
-----------------------------------
198
146
**_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR **:
@@ -307,7 +255,7 @@ Extensions to the C++23 modules ``std`` and ``std.compat``
307
255
----------------------------------------------------------
308
256
309
257
Like other major implementations, libc++ provides C++23 modules ``std `` and
310
- ``std.compat `` in C++20 as an extension"
258
+ ``std.compat `` in C++20 as an extension.
311
259
312
260
Constant-initialized std::string
313
261
--------------------------------
@@ -386,3 +334,38 @@ specific locale is imbued, the IO with the underlying stream happens with
386
334
regular ``char `` elements, which are converted to/from wide characters
387
335
according to the locale. Note that this doesn't behave as expected if the
388
336
stream has been set in Unicode mode.
337
+
338
+
339
+ Third-party Integrations
340
+ ========================
341
+
342
+ Libc++ provides integration with a few third-party tools.
343
+
344
+ GDB Pretty printers for libc++
345
+ ------------------------------
346
+
347
+ GDB does not support pretty-printing of libc++ symbols by default. However, libc++ does
348
+ provide pretty-printers itself. Those can be used as:
349
+
350
+ .. code-block :: bash
351
+
352
+ $ gdb -ex " source <libcxx>/utils/gdb/libcxx/printers.py" \
353
+ -ex " python register_libcxx_printer_loader()" \
354
+ < args>
355
+
356
+
357
+ .. _include-what-you-use :
358
+
359
+ include-what-you-use (IWYU)
360
+ ---------------------------
361
+
362
+ libc++ provides an IWYU `mapping file <https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md >`_,
363
+ which drastically improves the accuracy of the tool when using libc++. To use the mapping file with
364
+ IWYU, you should run the tool like so:
365
+
366
+ .. code-block :: bash
367
+
368
+ $ include-what-you-use -Xiwyu --mapping_file=/path/to/libcxx/include/libcxx.imp file.cpp
369
+
370
+ If you would prefer to not use that flag, then you can replace ``/path/to/include-what-you-use/share/libcxx.imp ``
371
+ file with the libc++-provided ``libcxx.imp `` file.
0 commit comments