Document Dual ABI for std::ios_base::failure
[official-gcc.git] / libstdc++-v3 / doc / html / faq.html
bloba0208269dd8d8858969885b499665f278e4900bf
1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Frequently Asked Questions</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><meta name="keywords" content="ISO C++, runtime, library" /><link rel="home" href="index.html" title="The GNU C++ Library" /><link rel="up" href="bk03.html" title="" /><link rel="prev" href="bk03.html" title="" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Frequently Asked Questions</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03.html">Prev</a> </td><th width="60%" align="center"></th><td width="20%" align="right"> </td></tr></table><hr /></div><div class="article"><div class="titlepage"><div><div><h1 class="title"><a id="faq"></a>Frequently Asked Questions</h1></div><div><p class="copyright">Copyright ©
3 2008-2018
5 <a class="link" href="https://www.fsf.org" target="_top">FSF</a>
6 </p></div></div><hr /></div><div class="qandaset"><a id="faq.faq"></a><dl><dt></dt><dd><dl><dt>1.1. <a href="faq.html#faq.what">
7 What is libstdc++?
8 </a></dt><dt>1.2. <a href="faq.html#faq.why">
9 Why should I use libstdc++?
10 </a></dt><dt>1.3. <a href="faq.html#faq.who">
11 Who's in charge of it?
12 </a></dt><dt>1.4. <a href="faq.html#faq.when">
13 When is libstdc++ going to be finished?
14 </a></dt><dt>1.5. <a href="faq.html#faq.how">
15 How do I contribute to the effort?
16 </a></dt><dt>1.6. <a href="faq.html#faq.whereis_old">
17 What happened to the older libg++? I need that!
18 </a></dt><dt>1.7. <a href="faq.html#faq.more_questions">
19 What if I have more questions?
20 </a></dt></dl></dd><dt></dt><dd><dl><dt>2.1. <a href="faq.html#faq.license.what">
21 What are the license terms for libstdc++?
22 </a></dt><dt>2.2. <a href="faq.html#faq.license.any_program">
23 So any program which uses libstdc++ falls under the GPL?
24 </a></dt><dt>2.3. <a href="faq.html#faq.license.lgpl">
25 How is that different from the GNU {Lesser,Library} GPL?
26 </a></dt><dt>2.4. <a href="faq.html#faq.license.what_restrictions">
27 I see. So, what restrictions are there on programs that use the library?
28 </a></dt></dl></dd><dt></dt><dd><dl><dt>3.1. <a href="faq.html#faq.how_to_install">How do I install libstdc++?
29 </a></dt><dt>3.2. <a href="faq.html#faq.how_to_get_sources">How does one get current libstdc++ sources?
30 </a></dt><dt>3.3. <a href="faq.html#faq.how_to_test">How do I know if it works?
31 </a></dt><dt>3.4. <a href="faq.html#faq.how_to_set_paths">How do I insure that the dynamically linked library will be found?
32 </a></dt><dt>3.5. <a href="faq.html#faq.what_is_libsupcxx">
33 What's libsupc++?
34 </a></dt><dt>3.6. <a href="faq.html#faq.size">
35 This library is HUGE!
36 </a></dt></dl></dd><dt></dt><dd><dl><dt>4.1. <a href="faq.html#faq.other_compilers">
37 Can libstdc++ be used with non-GNU compilers?
38 </a></dt><dt>4.2. <a href="faq.html#faq.solaris_long_long">
39 No 'long long' type on Solaris?
40 </a></dt><dt>4.3. <a href="faq.html#faq.predefined">
41 _XOPEN_SOURCE and _GNU_SOURCE are always defined?
42 </a></dt><dt>4.4. <a href="faq.html#faq.darwin_ctype">
43 Mac OS X ctype.h is broken! How can I fix it?
44 </a></dt><dt>4.5. <a href="faq.html#faq.threads_i386">
45 Threading is broken on i386?
46 </a></dt><dt>4.6. <a href="faq.html#faq.atomic_mips">
47 MIPS atomic operations
48 </a></dt><dt>4.7. <a href="faq.html#faq.linux_glibc">
49 Recent GNU/Linux glibc required?
50 </a></dt><dt>4.8. <a href="faq.html#faq.freebsd_wchar">
51 Can't use wchar_t/wstring on FreeBSD
52 </a></dt></dl></dd><dt></dt><dd><dl><dt>5.1. <a href="faq.html#faq.what_works">
53 What works already?
54 </a></dt><dt>5.2. <a href="faq.html#faq.standard_bugs">
55 Bugs in the ISO C++ language or library specification
56 </a></dt><dt>5.3. <a href="faq.html#faq.compiler_bugs">
57 Bugs in the compiler (gcc/g++) and not libstdc++
58 </a></dt></dl></dd><dt></dt><dd><dl><dt>6.1. <a href="faq.html#faq.stream_reopening_fails">
59 Reopening a stream fails
60 </a></dt><dt>6.2. <a href="faq.html#faq.wefcxx_verbose">
61 -Weffc++ complains too much
62 </a></dt><dt>6.3. <a href="faq.html#faq.ambiguous_overloads">
63 Ambiguous overloads after including an old-style header
64 </a></dt><dt>6.4. <a href="faq.html#faq.v2_headers">
65 The g++-3 headers are not ours
66 </a></dt><dt>6.5. <a href="faq.html#faq.boost_concept_checks">
67 Errors about *Concept and
68 constraints in the STL
69 </a></dt><dt>6.6. <a href="faq.html#faq.dlopen_crash">
70 Program crashes when using library code in a
71 dynamically-loaded library
72 </a></dt><dt>6.7. <a href="faq.html#faq.memory_leaks">
73 “Memory leaks” in containers
74 </a></dt><dt>6.8. <a href="faq.html#faq.list_size_on">
75 list::size() is O(n)!
76 </a></dt><dt>6.9. <a href="faq.html#faq.easy_to_fix">
77 Aw, that's easy to fix!
78 </a></dt></dl></dd><dt></dt><dd><dl><dt>7.1. <a href="faq.html#faq.iterator_as_pod">
79 string::iterator is not char*;
80 vector&lt;T&gt;::iterator is not T*
81 </a></dt><dt>7.2. <a href="faq.html#faq.what_is_next">
82 What's next after libstdc++?
83 </a></dt><dt>7.3. <a href="faq.html#faq.sgi_stl">
84 What about the STL from SGI?
85 </a></dt><dt>7.4. <a href="faq.html#faq.extensions_and_backwards_compat">
86 Extensions and Backward Compatibility
87 </a></dt><dt>7.5. <a href="faq.html#faq.tr1_support">
88 Does libstdc++ support TR1?
89 </a></dt><dt>7.6. <a href="faq.html#faq.get_iso_cxx">How do I get a copy of the ISO C++ Standard?
90 </a></dt><dt>7.7. <a href="faq.html#faq.what_is_abi">
91 What's an ABI and why is it so messy?
92 </a></dt><dt>7.8. <a href="faq.html#faq.size_equals_capacity">
93 How do I make std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size?
94 </a></dt></dl></dd></dl><table border="0" style="width: 100%;"><colgroup><col align="left" width="1%" /><col /></colgroup><tbody><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>1.1. <a href="faq.html#faq.what">
95 What is libstdc++?
96 </a></dt><dt>1.2. <a href="faq.html#faq.why">
97 Why should I use libstdc++?
98 </a></dt><dt>1.3. <a href="faq.html#faq.who">
99 Who's in charge of it?
100 </a></dt><dt>1.4. <a href="faq.html#faq.when">
101 When is libstdc++ going to be finished?
102 </a></dt><dt>1.5. <a href="faq.html#faq.how">
103 How do I contribute to the effort?
104 </a></dt><dt>1.6. <a href="faq.html#faq.whereis_old">
105 What happened to the older libg++? I need that!
106 </a></dt><dt>1.7. <a href="faq.html#faq.more_questions">
107 What if I have more questions?
108 </a></dt></dl></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.what"></a><a id="faq.what.q"></a><p><strong>1.1.</strong></p></td><td align="left" valign="top"><p>
109 What is libstdc++?
110 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="faq.what.a"></a></td><td align="left" valign="top"><p>
111 The GNU Standard C++ Library v3 is an ongoing project to
112 implement the ISO 14882 C++ Standard Library as described in
113 clauses 20 through 33 and annex D (prior to the 2017 standard
114 the library clauses started with 17). For those who want to see
115 exactly how far the project has come, or just want the latest
116 bleeding-edge code, the up-to-date source is available over
117 anonymous SVN, and can be browsed over the
118 <a class="link" href="https://gcc.gnu.org/svn.html" target="_top">web</a>.
119 </p><p>
120 N.B. The library is called libstdc++ <span class="emphasis"><em>not</em></span> stdlibc++.
121 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.why"></a><a id="q-why"></a><p><strong>1.2.</strong></p></td><td align="left" valign="top"><p>
122 Why should I use libstdc++?
123 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-why"></a></td><td align="left" valign="top"><p>
124 The completion of the initial ISO C++ standardization effort gave the C++
125 community a powerful set of reuseable tools in the form of the C++
126 Standard Library. However, for several years C++ implementations were
127 (as the Draft Standard used to say) <span class="quote"><span class="quote">incomplet and
128 incorrekt</span></span>, and many suffered from limitations of the compilers
129 that used them.
130 </p><p>
131 The GNU compiler collection
132 (<span class="command"><strong>gcc</strong></span>, <span class="command"><strong>g++</strong></span>, etc) is widely
133 considered to be one of the leading compilers in the world. Its
134 development is overseen by the
135 <a class="link" href="https://gcc.gnu.org/" target="_top">GCC team</a>. All of
136 the rapid development and near-legendary
137 <a class="link" href="https://gcc.gnu.org/buildstat.html" target="_top">portability</a>
138 that are the hallmarks of an open-source project are applied to libstdc++.
139 </p><p>
140 All of the standard classes and functions from C++98/C++03, C++11 and C++14
141 (such as <code class="classname">string</code>,
142 <code class="classname">vector&lt;&gt;</code>, iostreams, algorithms etc.)
143 are freely available and attempt to be fully compliant.
144 Work is ongoing to complete support for the current revision of the
145 ISO C++ Standard.
146 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.who"></a><a id="q-who"></a><p><strong>1.3.</strong></p></td><td align="left" valign="top"><p>
147 Who's in charge of it?
148 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-who"></a></td><td align="left" valign="top"><p>
149 The libstdc++ project is contributed to by several developers
150 all over the world, in the same way as GCC or the Linux kernel.
151 The current maintainers are listed in the
152 <a class="link" href="https://gcc.gnu.org/viewcvs/gcc/trunk/MAINTAINERS?view=co" target="_top"><code class="filename">MAINTAINERS</code></a>
153 file (look for "c++ runtime libs").
154 </p><p>
155 Development and discussion is held on the libstdc++ mailing
156 list. Subscribing to the list, or searching the list
157 archives, is open to everyone. You can read instructions for
158 doing so on the <a class="link" href="https://gcc.gnu.org/lists.html" target="_top">GCC mailing lists</a> page.
159 If you have questions, ideas, code, or are just curious, sign up!
160 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.when"></a><a id="q-when"></a><p><strong>1.4.</strong></p></td><td align="left" valign="top"><p>
161 When is libstdc++ going to be finished?
162 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-when"></a></td><td align="left" valign="top"><p>
163 Nathan Myers gave the best of all possible answers, responding to
164 a Usenet article asking this question: <span class="emphasis"><em>Sooner, if you
165 help.</em></span>
166 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.how"></a><a id="q-how"></a><p><strong>1.5.</strong></p></td><td align="left" valign="top"><p>
167 How do I contribute to the effort?
168 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-how"></a></td><td align="left" valign="top"><p>
169 See the <a class="link" href="manual/appendix_contributing.html" title="Appendix A.  Contributing">Contributing</a> section in
170 the manual. Subscribing to the mailing list (see above, or
171 the homepage) is a very good idea if you have something to
172 contribute, or if you have spare time and want to
173 help. Contributions don't have to be in the form of source code;
174 anybody who is willing to help write documentation, for example,
175 or has found a bug in code that we all thought was working and is
176 willing to provide details, is more than welcome!
177 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.whereis_old"></a><a id="q-whereis_old"></a><p><strong>1.6.</strong></p></td><td align="left" valign="top"><p>
178 What happened to the older libg++? I need that!
179 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-whereis_old"></a></td><td align="left" valign="top"><p>
180 The last libg++ README states
181 <span class="quote"><span class="quote">This package is considered obsolete and is no longer
182 being developed.</span></span>
183 It should not be used for new projects, and won't even compile with
184 recent releases of GCC (or most other C++ compilers).
185 </p><p>
186 More information can be found in the
187 <a class="link" href="manual/backwards.html" title="Backwards Compatibility">Backwards
188 Compatibility</a> section of the libstdc++ manual.
189 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.more_questions"></a><a id="q-more_questions"></a><p><strong>1.7.</strong></p></td><td align="left" valign="top"><p>
190 What if I have more questions?
191 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-more_questions"></a></td><td align="left" valign="top"><p>
192 If you have read the documentation, and your question remains
193 unanswered, then just ask the mailing list. At present, you do not
194 need to be subscribed to the list to send a message to it. More
195 information is available on the homepage (including how to browse
196 the list archives); to send a message to the list,
197 use <code class="email">&lt;<a class="email" href="mailto:libstdc++@gcc.gnu.org">libstdc++@gcc.gnu.org</a>&gt;</code>.
198 </p><p>
199 If you have a question that you think should be included
200 here, or if you have a question <span class="emphasis"><em>about</em></span> a question/answer
201 here, please send email to the libstdc++ mailing list, as above.
202 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>2.1. <a href="faq.html#faq.license.what">
203 What are the license terms for libstdc++?
204 </a></dt><dt>2.2. <a href="faq.html#faq.license.any_program">
205 So any program which uses libstdc++ falls under the GPL?
206 </a></dt><dt>2.3. <a href="faq.html#faq.license.lgpl">
207 How is that different from the GNU {Lesser,Library} GPL?
208 </a></dt><dt>2.4. <a href="faq.html#faq.license.what_restrictions">
209 I see. So, what restrictions are there on programs that use the library?
210 </a></dt></dl></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.license.what"></a><a id="q-license.what"></a><p><strong>2.1.</strong></p></td><td align="left" valign="top"><p>
211 What are the license terms for libstdc++?
212 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-license.what"></a></td><td align="left" valign="top"><p>
213 See <a class="link" href="manual/license.html" title="License">our license description</a>
214 for these and related questions.
215 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.license.any_program"></a><a id="q-license.any_program"></a><p><strong>2.2.</strong></p></td><td align="left" valign="top"><p>
216 So any program which uses libstdc++ falls under the GPL?
217 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-license.any_program"></a></td><td align="left" valign="top"><p>
218 No. The special exception permits use of the library in
219 proprietary applications.
220 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.license.lgpl"></a><a id="q-license.lgpl"></a><p><strong>2.3.</strong></p></td><td align="left" valign="top"><p>
221 How is that different from the GNU {Lesser,Library} GPL?
222 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-license.lgpl"></a></td><td align="left" valign="top"><p>
223 The LGPL requires that users be able to replace the LGPL code with a
224 modified version; this is trivial if the library in question is a C
225 shared library. But there's no way to make that work with C++, where
226 much of the library consists of inline functions and templates, which
227 are expanded inside the code that uses the library. So to allow people
228 to replace the library code, someone using the library would have to
229 distribute their own source, rendering the LGPL equivalent to the GPL.
230 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.license.what_restrictions"></a><a id="q-license.what_restrictions"></a><p><strong>2.4.</strong></p></td><td align="left" valign="top"><p>
231 I see. So, what restrictions are there on programs that use the library?
232 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-license.what_restrictions"></a></td><td align="left" valign="top"><p>
233 None. We encourage such programs to be released as free software,
234 but we won't punish you or sue you if you choose otherwise.
235 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>3.1. <a href="faq.html#faq.how_to_install">How do I install libstdc++?
236 </a></dt><dt>3.2. <a href="faq.html#faq.how_to_get_sources">How does one get current libstdc++ sources?
237 </a></dt><dt>3.3. <a href="faq.html#faq.how_to_test">How do I know if it works?
238 </a></dt><dt>3.4. <a href="faq.html#faq.how_to_set_paths">How do I insure that the dynamically linked library will be found?
239 </a></dt><dt>3.5. <a href="faq.html#faq.what_is_libsupcxx">
240 What's libsupc++?
241 </a></dt><dt>3.6. <a href="faq.html#faq.size">
242 This library is HUGE!
243 </a></dt></dl></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.how_to_install"></a><a id="q-how_to_install"></a><p><strong>3.1.</strong></p></td><td align="left" valign="top"><p>How do I install libstdc++?
244 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-how_to_install"></a></td><td align="left" valign="top"><p>
245 Often libstdc++ comes pre-installed as an integral part of many
246 existing GNU/Linux and Unix systems, as well as many embedded
247 development tools. It may be necessary to install extra
248 development packages to get the headers, or the documentation, or
249 the source: please consult your vendor for details.
250 </p><p>
251 To build and install from the GNU GCC sources, please consult the
252 <a class="link" href="manual/setup.html" title="Chapter 2. Setup">setup
253 documentation</a> for detailed
254 instructions. You may wish to browse those files ahead
255 of time to get a feel for what's required.
256 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.how_to_get_sources"></a><a id="q-how_to_get_sources"></a><p><strong>3.2.</strong></p></td><td align="left" valign="top"><p>How does one get current libstdc++ sources?
257 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-how_to_get_sources"></a></td><td align="left" valign="top"><p>
258 Libstdc++ sources for all official releases can be obtained as
259 part of the GCC sources, available from various sites and
260 mirrors. A full <a class="link" href="https://gcc.gnu.org/mirrors.html" target="_top">list of
261 download sites</a> is provided on the main GCC site.
262 </p><p>
263 Current libstdc++ sources can always be checked out of the main
264 GCC source repository using the appropriate version control
265 tool. At this time, that tool
266 is <span class="application">Subversion</span>.
267 </p><p>
268 <span class="application">Subversion</span>, or <acronym class="acronym">SVN</acronym>, is
269 one of several revision control packages. It was selected for GNU
270 projects because it's free (speech), free (beer), and very high
271 quality. The <a class="link" href="http://subversion.tigris.org" target="_top"> Subversion
272 home page</a> has a better description.
273 </p><p>
274 The <span class="quote"><span class="quote">anonymous client checkout</span></span> feature of SVN is
275 similar to anonymous FTP in that it allows anyone to retrieve
276 the latest libstdc++ sources.
277 </p><p>
278 For more information
279 see <a class="link" href="https://gcc.gnu.org/svn.html" target="_top"><acronym class="acronym">SVN</acronym>
280 details</a>.
281 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.how_to_test"></a><a id="q-how_to_test"></a><p><strong>3.3.</strong></p></td><td align="left" valign="top"><p>How do I know if it works?
282 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-how_to_test"></a></td><td align="left" valign="top"><p>
283 Libstdc++ comes with its own validation testsuite, which includes
284 conformance testing, regression testing, ABI testing, and
285 performance testing. Please consult the
286 <a class="link" href="http://gcc.gnu.org/install/test.html" target="_top">testing
287 documentation</a> for GCC and
288 <a class="link" href="manual/test.html" title="Testing">Testing</a> in the libstdc++
289 manual for more details.
290 </p><p>
291 If you find bugs in the testsuite programs themselves, or if you
292 think of a new test program that should be added to the suite,
293 <span class="emphasis"><em>please</em></span> write up your idea and send it to the list!
294 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.how_to_set_paths"></a><a id="q-how_to_set_paths"></a><p><strong>3.4.</strong></p></td><td align="left" valign="top"><p>How do I insure that the dynamically linked library will be found?
295 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-how_to_set_paths"></a></td><td align="left" valign="top"><p>
296 Depending on your platform and library version, the error message might
297 be similar to one of the following:
298 </p><pre class="screen">
299 ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
301 /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
302 </pre><p>
303 This doesn't mean that the shared library isn't installed, only
304 that the dynamic linker can't find it. When a dynamically-linked
305 executable is run the linker finds and loads the required shared
306 libraries by searching a pre-configured list of directories. If
307 the directory where you've installed libstdc++ is not in this list
308 then the libraries won't be found.
309 </p><p>
310 If you already have an older version of libstdc++ installed then the
311 error might look like one of the following instead:
312 </p><pre class="screen">
313 ./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found
314 ./a.out: /usr/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found
315 </pre><p>
316 This means the linker found <code class="filename">/usr/lib/libstdc++.so.6</code>
317 but that library belongs to an older version of GCC than was used to
318 compile and link the program <code class="filename">a.out</code> (or some part
319 of it). The program depends on code defined in the newer libstdc++
320 that belongs to the newer version of GCC, so the linker must be told
321 how to find the newer libstdc++ shared library.
322 </p><p>
323 The simplest way to fix this is
324 to use the <code class="envar">LD_LIBRARY_PATH</code> environment variable,
325 which is a colon-separated list of directories in which the linker
326 will search for shared libraries:
327 </p><pre class="screen"><span class="command"><strong>
328 export LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
329 </strong></span></pre><p>
330 Here the shell variable <code class="varname">${prefix}</code> is assumed to contain
331 the directory prefix where GCC was installed to. The directory containing
332 the library might depend on whether you want the 32-bit or 64-bit copy
333 of the library, so for example would be
334 <code class="filename">${prefix}/lib64</code> on some systems.
335 The exact environment variable to use will depend on your
336 platform, e.g. <code class="envar">DYLD_LIBRARY_PATH</code> for Darwin,
337 <code class="envar">LD_LIBRARY_PATH_32</code>/<code class="envar">LD_LIBRARY_PATH_64</code>
338 for Solaris 32-/64-bit,
339 and <code class="envar">SHLIB_PATH</code> for HP-UX.
340 </p><p>
341 See the man pages for <span class="command"><strong>ld</strong></span>, <span class="command"><strong>ldd</strong></span>
342 and <span class="command"><strong>ldconfig</strong></span> for more information. The dynamic
343 linker has different names on different platforms but the man page
344 is usually called something such as <code class="filename">ld.so</code>,
345 <code class="filename">rtld</code> or <code class="filename">dld.so</code>.
346 </p><p>
347 Using <code class="envar">LD_LIBRARY_PATH</code> is not always the best solution,
348 <a class="link" href="manual/using_dynamic_or_shared.html#manual.intro.using.linkage.dynamic" title="Finding Dynamic or Shared Libraries">Finding Dynamic or Shared
349 Libraries</a> in the manual gives some alternatives.
350 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.what_is_libsupcxx"></a><a id="q-what_is_libsupcxx"></a><p><strong>3.5.</strong></p></td><td align="left" valign="top"><p>
351 What's libsupc++?
352 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-what_is_libsupcxx"></a></td><td align="left" valign="top"><p>
353 If the only functions from <code class="filename">libstdc++.a</code>
354 which you need are language support functions (those listed in
355 <a class="link" href="manual/support.html" title="Chapter 4.  Support">clause 18</a> of the
356 standard, e.g., <code class="function">new</code> and
357 <code class="function">delete</code>), then try linking against
358 <code class="filename">libsupc++.a</code>, which is a subset of
359 <code class="filename">libstdc++.a</code>. (Using <span class="command"><strong>gcc</strong></span>
360 instead of <span class="command"><strong>g++</strong></span> and explicitly linking in
361 <code class="filename">libsupc++.a</code> via <code class="option">-lsupc++</code>
362 for the final link step will do it). This library contains only
363 those support routines, one per object file. But if you are
364 using anything from the rest of the library, such as IOStreams
365 or vectors, then you'll still need pieces from
366 <code class="filename">libstdc++.a</code>.
367 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.size"></a><a id="q-size"></a><p><strong>3.6.</strong></p></td><td align="left" valign="top"><p>
368 This library is HUGE!
369 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-size"></a></td><td align="left" valign="top"><p>
370 Usually the size of libraries on disk isn't noticeable. When a
371 link editor (or simply <span class="quote"><span class="quote">linker</span></span>) pulls things from a
372 static archive library, only the necessary object files are copied
373 into your executable, not the entire library. Unfortunately, even
374 if you only need a single function or variable from an object file,
375 the entire object file is extracted. (There's nothing unique to C++
376 or libstdc++ about this; it's just common behavior, given here
377 for background reasons.)
378 </p><p>
379 Some of the object files which make up
380 <code class="filename">libstdc++.a</code> are rather large.
381 If you create a statically-linked executable with
382 <code class="option">-static</code>, those large object files are suddenly part
383 of your executable. Historically the best way around this was to
384 only place a very few functions (often only a single one) in each
385 source/object file; then extracting a single function is the same
386 as extracting a single <code class="filename">.o</code> file. For libstdc++ this
387 is only possible to a certain extent; the object files in question contain
388 template classes and template functions, pre-instantiated, and
389 splitting those up causes severe maintenance headaches.
390 </p><p>
391 On supported platforms, libstdc++ takes advantage of garbage
392 collection in the GNU linker to get a result similar to separating
393 each symbol into a separate source and object files. On these platforms,
394 GNU ld can place each function and variable into its own
395 section in a <code class="filename">.o</code> file. The GNU linker can then perform
396 garbage collection on unused sections; this reduces the situation to only
397 copying needed functions into the executable, as before, but all
398 happens automatically.
399 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>4.1. <a href="faq.html#faq.other_compilers">
400 Can libstdc++ be used with non-GNU compilers?
401 </a></dt><dt>4.2. <a href="faq.html#faq.solaris_long_long">
402 No 'long long' type on Solaris?
403 </a></dt><dt>4.3. <a href="faq.html#faq.predefined">
404 _XOPEN_SOURCE and _GNU_SOURCE are always defined?
405 </a></dt><dt>4.4. <a href="faq.html#faq.darwin_ctype">
406 Mac OS X ctype.h is broken! How can I fix it?
407 </a></dt><dt>4.5. <a href="faq.html#faq.threads_i386">
408 Threading is broken on i386?
409 </a></dt><dt>4.6. <a href="faq.html#faq.atomic_mips">
410 MIPS atomic operations
411 </a></dt><dt>4.7. <a href="faq.html#faq.linux_glibc">
412 Recent GNU/Linux glibc required?
413 </a></dt><dt>4.8. <a href="faq.html#faq.freebsd_wchar">
414 Can't use wchar_t/wstring on FreeBSD
415 </a></dt></dl></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.other_compilers"></a><a id="q-other_compilers"></a><p><strong>4.1.</strong></p></td><td align="left" valign="top"><p>
416 Can libstdc++ be used with non-GNU compilers?
417 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-other_compilers"></a></td><td align="left" valign="top"><p>
418 Perhaps.
419 </p><p>
420 Since the goal of ISO Standardization is for all C++
421 implementations to be able to share code, libstdc++ should be
422 usable under any ISO-compliant compiler, at least in theory.
423 </p><p>
424 However, the reality is that libstdc++ is targeted and optimized
425 for GCC/G++. This means that often libstdc++ uses specific,
426 non-standard features of G++ that are not present in older
427 versions of proprietary compilers. It may take as much as a year or two
428 after an official release of GCC that contains these features for
429 proprietary tools to support these constructs.
430 </p><p>
431 Recent versions of libstdc++ are known to work with the Clang compiler.
432 In the near past, specific released versions of libstdc++ have
433 been known to work with versions of the EDG C++ compiler, and
434 vendor-specific proprietary C++ compilers such as the Intel ICC
435 C++ compiler.
436 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.solaris_long_long"></a><a id="q-solaris_long_long"></a><p><strong>4.2.</strong></p></td><td align="left" valign="top"><p>
437 No '<span class="type">long long</span>' type on Solaris?
438 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-solaris_long_long"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>
439 By default we try to support the C99 <span class="type">long long</span> type.
440 This requires that certain functions from your C library be present.
441 </p><p>
442 Up through release 3.0.2 the platform-specific tests performed by
443 libstdc++ were too general, resulting in a conservative approach
444 to enabling the <span class="type">long long</span> code paths. The most
445 commonly reported platform affected was Solaris.
446 </p><p>
447 This has been fixed for libstdc++ releases greater than 3.0.3.
448 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.predefined"></a><a id="q-predefined"></a><p><strong>4.3.</strong></p></td><td align="left" valign="top"><p>
449 <code class="constant">_XOPEN_SOURCE</code> and <code class="constant">_GNU_SOURCE</code> are always defined?
450 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-predefined"></a></td><td align="left" valign="top"><p>On Solaris, <span class="command"><strong>g++</strong></span> (but not <span class="command"><strong>gcc</strong></span>)
451 always defines the preprocessor macro
452 <code class="constant">_XOPEN_SOURCE</code>. On GNU/Linux, the same happens
453 with <code class="constant">_GNU_SOURCE</code>. (This is not an exhaustive list;
454 other macros and other platforms are also affected.)
455 </p><p>These macros are typically used in C library headers, guarding new
456 versions of functions from their older versions. The C++98 standard
457 library includes the C standard library, but it requires the C90
458 version, which for backwards-compatibility reasons is often not the
459 default for many vendors.
460 </p><p>More to the point, the C++ standard requires behavior which is only
461 available on certain platforms after certain symbols are defined.
462 Usually the issue involves I/O-related typedefs. In order to
463 ensure correctness, the compiler simply predefines those symbols.
464 </p><p>Note that it's not enough to <code class="literal">#define</code> them only when the library is
465 being built (during installation). Since we don't have an 'export'
466 keyword, much of the library exists as headers, which means that
467 the symbols must also be defined as your programs are parsed and
468 compiled.
469 </p><p>To see which symbols are defined, look for
470 <code class="varname">CPLUSPLUS_CPP_SPEC</code> in
471 the gcc config headers for your target (and try changing them to
472 see what happens when building complicated code). You can also run
473 <span class="command"><strong>g++ -E -dM - &lt; /dev/null"</strong></span> to display
474 a list of predefined macros for any particular installation.
475 </p><p>This has been discussed on the mailing lists
476 <a class="link" href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&amp;format=builtin-long&amp;sort=score&amp;words=_XOPEN_SOURCE+Solaris" target="_top">quite a bit</a>.
477 </p><p>This method is something of a wart. We'd like to find a cleaner
478 solution, but nobody yet has contributed the time.
479 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.darwin_ctype"></a><a id="q-darwin_ctype"></a><p><strong>4.4.</strong></p></td><td align="left" valign="top"><p>
480 Mac OS X <code class="filename">ctype.h</code> is broken! How can I fix it?
481 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-darwin_ctype"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>
482 This was a long-standing bug in the OS X support. Fortunately, the
483 <a class="link" href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html" target="_top">patch</a>
484 was quite simple, and well-known.
485 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.threads_i386"></a><a id="q-threads_i386"></a><p><strong>4.5.</strong></p></td><td align="left" valign="top"><p>
486 Threading is broken on i386?
487 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-threads_i386"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>Support for atomic integer operations was broken on i386
488 platforms. The assembly code accidentally used opcodes that are
489 only available on the i486 and later. So if you configured GCC
490 to target, for example, i386-linux, but actually used the programs
491 on an i686, then you would encounter no problems. Only when
492 actually running the code on a i386 will the problem appear.
493 </p><p>This is fixed in 3.2.2.
494 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.atomic_mips"></a><a id="q-atomic_mips"></a><p><strong>4.6.</strong></p></td><td align="left" valign="top"><p>
495 MIPS atomic operations
496 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-atomic_mips"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>
497 The atomic locking routines for MIPS targets requires MIPS II
498 and later. A patch went in just after the 3.3 release to
499 make mips* use the generic implementation instead. You can also
500 configure for mipsel-elf as a workaround.
501 </p><p>
502 The mips*-*-linux* port continues to use the MIPS II routines, and more
503 work in this area is expected.
504 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.linux_glibc"></a><a id="q-linux_glibc"></a><p><strong>4.7.</strong></p></td><td align="left" valign="top"><p>
505 Recent GNU/Linux glibc required?
506 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-linux_glibc"></a></td><td align="left" valign="top"><p>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
507 5.0.1) and later uses localization and formatting code from the system
508 C library (glibc) version 2.2.5 which contains necessary bugfixes.
509 All GNU/Linux distros make more recent versions available now.
510 libstdc++ 4.6.0 and later require glibc 2.3 or later for this
511 localization and formatting code.
512 </p><p>The guideline is simple: the more recent the C++ library, the
513 more recent the C library. (This is also documented in the main
514 GCC installation instructions.)
515 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.freebsd_wchar"></a><a id="q-freebsd_wchar"></a><p><strong>4.8.</strong></p></td><td align="left" valign="top"><p>
516 Can't use <span class="type">wchar_t</span>/<code class="classname">wstring</code> on FreeBSD
517 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-freebsd_wchar"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>
518 Older versions of FreeBSD's C library do not have sufficient
519 support for wide character functions, and as a result the
520 libstdc++ configury decides that <span class="type">wchar_t</span> support should be
521 disabled. In addition, the libstdc++ platform checks that
522 enabled <span class="type">wchar_t</span> were quite strict, and not granular
523 enough to detect when the minimal support to
524 enable <span class="type">wchar_t</span> and C++ library structures
525 like <code class="classname">wstring</code> were present. This impacted Solaris,
526 Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
527 </p><p>
528 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>5.1. <a href="faq.html#faq.what_works">
529 What works already?
530 </a></dt><dt>5.2. <a href="faq.html#faq.standard_bugs">
531 Bugs in the ISO C++ language or library specification
532 </a></dt><dt>5.3. <a href="faq.html#faq.compiler_bugs">
533 Bugs in the compiler (gcc/g++) and not libstdc++
534 </a></dt></dl></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.what_works"></a><a id="q-what_works"></a><p><strong>5.1.</strong></p></td><td align="left" valign="top"><p>
535 What works already?
536 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-what_works"></a></td><td align="left" valign="top"><p>
537 Short answer: Pretty much everything <span class="emphasis"><em>works</em></span>
538 except for some corner cases. Support for localization
539 in <code class="classname">locale</code> may be incomplete on some non-GNU
540 platforms. Also dependent on the underlying platform is support
541 for <span class="type">wchar_t</span> and <span class="type">long long</span> specializations,
542 and details of thread support.
543 </p><p>
544 Long answer: See the implementation status pages for
545 <a class="link" href="manual/status.html#status.iso.1998" title="C++ 1998/2003">C++98</a>,
546 <a class="link" href="manual/status.html#status.iso.tr1" title="C++ TR1">TR1</a>,
547 <a class="link" href="manual/status.html#status.iso.2011" title="C++ 2011">C++11</a>,
548 <a class="link" href="manual/status.html#status.iso.2014" title="C++ 2014">C++14</a>, and
549 <a class="link" href="manual/status.html#status.iso.2017" title="C++ 2017">C++17</a>.
550 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.standard_bugs"></a><a id="q-standard_bugs"></a><p><strong>5.2.</strong></p></td><td align="left" valign="top"><p>
551 Bugs in the ISO C++ language or library specification
552 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-standard_bugs"></a></td><td align="left" valign="top"><p>
553 Unfortunately, there are some.
554 </p><p>
555 For those people who are not part of the ISO Library Group
556 (i.e., nearly all of us needing to read this page in the first
557 place), a public list of the library defects is occasionally
558 published on <a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/" target="_top">the WG21
559 website</a>.
560 Many of these issues have resulted in
561 <a class="link" href="manual/bugs.html#manual.intro.status.bugs.iso" title="Standard Bugs">code changes in libstdc++</a>.
562 </p><p>
563 If you think you've discovered a new bug that is not listed,
564 please post a message describing your problem to the author of
565 the library issues list.
566 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.compiler_bugs"></a><a id="q-compiler_bugs"></a><p><strong>5.3.</strong></p></td><td align="left" valign="top"><p>
567 Bugs in the compiler (gcc/g++) and not libstdc++
568 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-compiler_bugs"></a></td><td align="left" valign="top"><p>
569 On occasion, the compiler is wrong. Please be advised that this
570 happens much less often than one would think, and avoid jumping to
571 conclusions.
572 </p><p>
573 First, examine the ISO C++ standard. Second, try another compiler
574 or an older version of the GNU compilers. Third, you can find more
575 information on the libstdc++ and the GCC mailing lists: search
576 these lists with terms describing your issue.
577 </p><p>
578 Before reporting a bug, please examine the
579 <a class="link" href="https://gcc.gnu.org/bugs/" target="_top">bugs database</a>, with the
580 component set to <span class="quote">“<span class="quote">c++</span>”</span>.
581 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>6.1. <a href="faq.html#faq.stream_reopening_fails">
582 Reopening a stream fails
583 </a></dt><dt>6.2. <a href="faq.html#faq.wefcxx_verbose">
584 -Weffc++ complains too much
585 </a></dt><dt>6.3. <a href="faq.html#faq.ambiguous_overloads">
586 Ambiguous overloads after including an old-style header
587 </a></dt><dt>6.4. <a href="faq.html#faq.v2_headers">
588 The g++-3 headers are not ours
589 </a></dt><dt>6.5. <a href="faq.html#faq.boost_concept_checks">
590 Errors about *Concept and
591 constraints in the STL
592 </a></dt><dt>6.6. <a href="faq.html#faq.dlopen_crash">
593 Program crashes when using library code in a
594 dynamically-loaded library
595 </a></dt><dt>6.7. <a href="faq.html#faq.memory_leaks">
596 “Memory leaks” in containers
597 </a></dt><dt>6.8. <a href="faq.html#faq.list_size_on">
598 list::size() is O(n)!
599 </a></dt><dt>6.9. <a href="faq.html#faq.easy_to_fix">
600 Aw, that's easy to fix!
601 </a></dt></dl></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.stream_reopening_fails"></a><a id="q-stream_reopening_fails"></a><p><strong>6.1.</strong></p></td><td align="left" valign="top"><p>
602 Reopening a stream fails
603 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-stream_reopening_fails"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>
604 Prior to GCC 4.0 this was one of the most-reported non-bug reports.
605 Executing a sequence like this would fail:
606 </p><pre class="programlisting">
607 #include &lt;fstream&gt;
609 std::fstream fs("a_file");
610 // .
611 // . do things with fs...
612 // .
613 fs.close();
614 fs.open("a_new_file");
615 </pre><p>
616 All operations on the re-opened <code class="varname">fs</code> would fail, or at
617 least act very strangely, especially if <code class="varname">fs</code> reached the
618 EOF state on the previous file.
619 The original C++98 standard did not specify behavior in this case, and
620 the <a class="link" href="manual/bugs.html#manual.bugs.dr22">resolution of DR #22</a> was to
621 leave the state flags unchanged on a successful call to
622 <code class="function">open()</code>.
623 You had to insert a call to <code class="function">fs.clear()</code> between the
624 calls to <code class="function">close()</code> and <code class="function">open()</code>,
625 and then everything will work as expected.
626 <span class="emphasis"><em>Update:</em></span> For GCC 4.0 we implemented the resolution
627 of <a class="link" href="manual/bugs.html#manual.bugs.dr409">DR #409</a> and
628 <code class="function">open()</code>
629 now calls <code class="function">clear()</code> on success.
630 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.wefcxx_verbose"></a><a id="q-wefcxx_verbose"></a><p><strong>6.2.</strong></p></td><td align="left" valign="top"><p>
631 -Weffc++ complains too much
632 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-wefcxx_verbose"></a></td><td align="left" valign="top"><p>
633 Many warnings are emitted when <code class="option">-Weffc++</code> is used. Making
634 libstdc++ <code class="option">-Weffc++</code>-clean is not a goal of the project,
635 for a few reasons. Mainly, that option tries to enforce
636 object-oriented programming, while the Standard Library isn't
637 necessarily trying to be OO. The option also enforces outdated guidelines
638 from old editions of the books, and the advice isn't all relevant to
639 modern C++ (especially C++11 and later).
640 </p><p>
641 We do, however, try to have libstdc++ sources as clean as possible. If
642 you see some simple changes that pacify <code class="option">-Weffc++</code>
643 without other drawbacks, send us a patch.
644 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.ambiguous_overloads"></a><a id="q-ambiguous_overloads"></a><p><strong>6.3.</strong></p></td><td align="left" valign="top"><p>
645 Ambiguous overloads after including an old-style header
646 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-ambiguous_overloads"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>
647 Another problem is the <code class="literal">rel_ops</code> namespace and the template
648 comparison operator functions contained therein. If they become
649 visible in the same namespace as other comparison functions
650 (e.g., <span class="quote">“<span class="quote">using</span>”</span> them and the
651 <code class="filename">&lt;iterator&gt;</code> header),
652 then you will suddenly be faced with huge numbers of ambiguity
653 errors. This was discussed on the mailing list; Nathan Myers
654 <a class="link" href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html" target="_top">sums
655 things up here</a>. The collisions with vector/string iterator
656 types have been fixed for 3.1.
657 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.v2_headers"></a><a id="q-v2_headers"></a><p><strong>6.4.</strong></p></td><td align="left" valign="top"><p>
658 The g++-3 headers are <span class="emphasis"><em>not ours</em></span>
659 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-v2_headers"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>
660 If you are using headers in
661 <code class="filename">${prefix}/include/g++-3</code>, or if
662 the installed library's name looks like
663 <code class="filename">libstdc++-2.10.a</code> or
664 <code class="filename">libstdc++-libc6-2.10.so</code>, then
665 you are using the old libstdc++-v2 library, which is non-standard and
666 unmaintained. Do not report problems with -v2 to the -v3
667 mailing list.
668 </p><p>
669 For GCC versions 3.0 and 3.1 the libstdc++ header files are installed in
670 <code class="filename">${prefix}/include/g++-v3</code>
671 (see the 'v'?). Starting with version 3.2 the headers are installed in
672 <code class="filename">${prefix}/include/c++/${version}</code>
673 as this prevents headers from previous versions being found by mistake.
674 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.boost_concept_checks"></a><a id="q-boost_concept_checks"></a><p><strong>6.5.</strong></p></td><td align="left" valign="top"><p>
675 Errors about <span class="emphasis"><em>*Concept</em></span> and
676 <span class="emphasis"><em>constraints</em></span> in the STL
677 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-boost_concept_checks"></a></td><td align="left" valign="top"><p>
678 If you see compilation errors containing messages about
679 <span class="errortext">foo Concept</span> and something to do with a
680 <span class="errortext">constraints</span> member function, then most
681 likely you have violated one of the requirements for types used
682 during instantiation of template containers and functions. For
683 example, EqualityComparableConcept appears if your types must be
684 comparable with == and you have not provided this capability (a
685 typo, or wrong visibility, or you just plain forgot, etc).
686 </p><p>
687 More information, including how to optionally enable/disable the
688 checks, is available in the
689 <a class="link" href="manual/concept_checking.html" title="Concept Checking">Diagnostics</a>.
690 chapter of the manual.
691 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.dlopen_crash"></a><a id="q-dlopen_crash"></a><p><strong>6.6.</strong></p></td><td align="left" valign="top"><p>
692 Program crashes when using library code in a
693 dynamically-loaded library
694 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-dlopen_crash"></a></td><td align="left" valign="top"><p>
695 If you are using the C++ library across dynamically-loaded
696 objects, make certain that you are passing the correct options
697 when compiling and linking:
698 </p><div class="literallayout"><p><br />
699     Compile your library components:<br />
700     <span class="command"><strong>g++ -fPIC -c a.cc</strong></span><br />
701     <span class="command"><strong>g++ -fPIC -c b.cc</strong></span><br />
702     ...<br />
703     <span class="command"><strong>g++ -fPIC -c z.cc</strong></span><br />
704 <br />
705     Create your library:<br />
706     <span class="command"><strong>g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o</strong></span><br />
707 <br />
708     Link the executable:<br />
709     <span class="command"><strong>g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl</strong></span><br />
710     </p></div></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.memory_leaks"></a><a id="q-memory_leaks"></a><p><strong>6.7.</strong></p></td><td align="left" valign="top"><p>
711 <span class="quote">“<span class="quote">Memory leaks</span>”</span> in containers
712 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-memory_leaks"></a></td><td align="left" valign="top"><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This answer is old and probably no longer be relevant.</p></div><p>
713 A few people have reported that the standard containers appear
714 to leak memory when tested with memory checkers such as
715 <a class="link" href="http://valgrind.org/" target="_top"><span class="command"><strong>valgrind</strong></span></a>.
716 Under some (non-default) configurations the library's allocators keep
717 free memory in a
718 pool for later reuse, rather than returning it to the OS. Although
719 this memory is always reachable by the library and is never
720 lost, memory debugging tools can report it as a leak. If you
721 want to test the library for memory leaks please read
722 <a class="link" href="manual/debug.html#debug.memory" title="Memory Leak Hunting">Tips for memory leak hunting</a>
723 first.
724 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.list_size_on"></a><a id="q-list_size_on"></a><p><strong>6.8.</strong></p></td><td align="left" valign="top"><p>
725 <code class="code">list::size()</code> is O(n)!
726 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-list_size_on"></a></td><td align="left" valign="top"><p>
728 the <a class="link" href="manual/containers.html" title="Chapter 9.  Containers">Containers</a>
729 chapter.
730 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.easy_to_fix"></a><a id="q-easy_to_fix"></a><p><strong>6.9.</strong></p></td><td align="left" valign="top"><p>
731 Aw, that's easy to fix!
732 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-easy_to_fix"></a></td><td align="left" valign="top"><p>
733 If you have found a bug in the library and you think you have
734 a working fix, then send it in! The main GCC site has a page
735 on <a class="link" href="http://gcc.gnu.org/contribute.html" target="_top">submitting
736 patches</a> that covers the procedure, but for libstdc++ you
737 should also send the patch to our mailing list in addition to
738 the GCC patches mailing list. The libstdc++
739 <a class="link" href="manual/appendix_contributing.html" title="Appendix A.  Contributing">contributors' page</a>
740 also talks about how to submit patches.
741 </p><p>
742 In addition to the description, the patch, and the ChangeLog
743 entry, it is a Good Thing if you can additionally create a small
744 test program to test for the presence of the bug that your patch
745 fixes. Bugs have a way of being reintroduced; if an old bug
746 creeps back in, it will be caught immediately by the testsuite -
747 but only if such a test exists.
748 </p></td></tr><tr class="toc"><td align="left" valign="top" colspan="2"><dl><dt>7.1. <a href="faq.html#faq.iterator_as_pod">
749 string::iterator is not char*;
750 vector&lt;T&gt;::iterator is not T*
751 </a></dt><dt>7.2. <a href="faq.html#faq.what_is_next">
752 What's next after libstdc++?
753 </a></dt><dt>7.3. <a href="faq.html#faq.sgi_stl">
754 What about the STL from SGI?
755 </a></dt><dt>7.4. <a href="faq.html#faq.extensions_and_backwards_compat">
756 Extensions and Backward Compatibility
757 </a></dt><dt>7.5. <a href="faq.html#faq.tr1_support">
758 Does libstdc++ support TR1?
759 </a></dt><dt>7.6. <a href="faq.html#faq.get_iso_cxx">How do I get a copy of the ISO C++ Standard?
760 </a></dt><dt>7.7. <a href="faq.html#faq.what_is_abi">
761 What's an ABI and why is it so messy?
762 </a></dt><dt>7.8. <a href="faq.html#faq.size_equals_capacity">
763 How do I make std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size?
764 </a></dt></dl></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.iterator_as_pod"></a><a id="faq.iterator_as_pod_q"></a><p><strong>7.1.</strong></p></td><td align="left" valign="top"><p>
765 <code class="classname">string::iterator</code> is not <code class="code">char*</code>;
766 <code class="classname">vector&lt;T&gt;::iterator</code> is not <code class="code">T*</code>
767 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="faq.iterator_as_pod_a"></a></td><td align="left" valign="top"><p>
768 If you have code that depends on container&lt;T&gt; iterators
769 being implemented as pointer-to-T, your code is broken. It's
770 considered a feature, not a bug, that libstdc++ points this out.
771 </p><p>
772 While there are arguments for iterators to be implemented in
773 that manner, A) they aren't very good ones in the long term,
774 and B) they were never guaranteed by the Standard anyway. The
775 type-safety achieved by making iterators a real class rather
776 than a typedef for <span class="type">T*</span> outweighs nearly all opposing
777 arguments.
778 </p><p>
779 Code which does assume that a vector/string iterator <code class="varname">i</code>
780 is a pointer can often be fixed by changing <code class="varname">i</code> in
781 certain expressions to <code class="varname">&amp;*i</code>.
782 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.what_is_next"></a><a id="q-what_is_next"></a><p><strong>7.2.</strong></p></td><td align="left" valign="top"><p>
783 What's next after libstdc++?
784 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-what_is_next"></a></td><td align="left" valign="top"><p>
785 The goal of libstdc++ is to produce a
786 fully-compliant, fully-portable Standard Library.
787 While the C++ Standard continues to evolve the libstdc++ will
788 continue to track it.
789 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.sgi_stl"></a><a id="q-sgi_stl"></a><p><strong>7.3.</strong></p></td><td align="left" valign="top"><p>
790 What about the STL from SGI?
791 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-sgi_stl"></a></td><td align="left" valign="top"><p>
792 The STL (Standard Template Library) was the inspiration for large chunks
793 of the C++ Standard Library, but the terms are not interchangeable and
794 they don't mean the same thing. The C++ Standard Library includes lots of
795 things that didn't come from the STL, and some of them aren't even
796 templates, such as <code class="classname">std::locale</code> and
797 <code class="classname">std::thread</code>.
798 </p><p>
799 Libstdc++-v3 incorporates a lot of code from
800 <a class="link" href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/" target="_top">the SGI STL</a>
801 (the final merge was from
802 <a class="link" href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/whats_new.html" target="_top">release 3.3</a>).
803 The code in libstdc++ contains many fixes and changes compared to the
804 original SGI code.
805 </p><p>
806 In particular, <code class="classname">string</code> is not from SGI and makes no
807 use of their "rope" class (although that is included as an optional
808 extension), neither is <code class="classname">valarray</code> nor some others.
809 Classes like <code class="classname">vector&lt;&gt;</code> were from SGI, but have
810 been extensively modified.
811 </p><p>
812 More information on the evolution of libstdc++ can be found at the
813 <a class="link" href="manual/api.html" title="API Evolution and Deprecation History">API
814 evolution</a>
815 and <a class="link" href="manual/backwards.html" title="Backwards Compatibility">backwards
816 compatibility</a> documentation.
817 </p><p>
818 The <a class="link" href="https://web.archive.org/web/20171225062613/http://www.sgi.com/tech/stl/FAQ.html" target="_top">FAQ</a>
819 for SGI's STL is still recommended reading.
820 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.extensions_and_backwards_compat"></a><a id="q-extensions_and_backwards_compat"></a><p><strong>7.4.</strong></p></td><td align="left" valign="top"><p>
821 Extensions and Backward Compatibility
822 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-extensions_and_backwards_compat"></a></td><td align="left" valign="top"><p>
823 See the <a class="link" href="manual/backwards.html" title="Backwards Compatibility">link</a> on backwards compatibility and <a class="link" href="manual/api.html" title="API Evolution and Deprecation History">link</a> on evolution.
824 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.tr1_support"></a><a id="q-tr1_support"></a><p><strong>7.5.</strong></p></td><td align="left" valign="top"><p>
825 Does libstdc++ support TR1?
826 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-tr1_support"></a></td><td align="left" valign="top"><p>
827 Yes.
828 </p><p>
829 The C++ Standard Library
830 <a class="link" href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf" target="_top">
831 Technical Report 1</a> added many new features to the library.
832 </p><p>
833 The implementation status of TR1 in libstdc++ can be tracked
834 <a class="link" href="manual/status.html#status.iso.tr1" title="C++ TR1">on the TR1 status page</a>.
835 </p><p>
836 New code should probably not use TR1, because almost everything in it has
837 been added to the main C++ Standard Library (usually with significant
838 improvements).
839 The TR1 implementation in libstdc++ is no longer actively maintained.
840 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.get_iso_cxx"></a><a id="q-get_iso_cxx"></a><p><strong>7.6.</strong></p></td><td align="left" valign="top"><p>How do I get a copy of the ISO C++ Standard?
841 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-get_iso_cxx"></a></td><td align="left" valign="top"><p>
842 Please refer to the <a class="link" href="manual/appendix_contributing.html" title="Appendix A.  Contributing">Contributing</a>
843 section in our manual.
844 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.what_is_abi"></a><a id="q-what_is_abi"></a><p><strong>7.7.</strong></p></td><td align="left" valign="top"><p>
845 What's an ABI and why is it so messy?
846 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-what_is_abi"></a></td><td align="left" valign="top"><p>
847 <acronym class="acronym">ABI</acronym> stands for <span class="quote">“<span class="quote">Application Binary
848 Interface</span>”</span>. Conventionally, it refers to a great
849 mass of details about how arguments are arranged on the call
850 stack and/or in registers, and how various types are arranged
851 and padded in structs. A single CPU design may suffer
852 multiple ABIs designed by different development tool vendors
853 who made different choices, or even by the same vendor for
854 different target applications or compiler versions. In ideal
855 circumstances the CPU designer presents one ABI and all the
856 OSes and compilers use it. In practice every ABI omits
857 details that compiler implementers (consciously or
858 accidentally) must choose for themselves.
859 </p><p>
860 That ABI definition suffices for compilers to generate code so a
861 program can interact safely with an OS and its lowest-level libraries.
862 Users usually want an ABI to encompass more detail, allowing libraries
863 built with different compilers (or different releases of the same
864 compiler!) to be linked together. For C++, this includes many more
865 details than for C, and most CPU designers (for good reasons elaborated
866 below) have not stepped up to publish C++ ABIs. Such an ABI has been
867 defined for the Itanium architecture (see
868 <a class="link" href="https://itanium-cxx-abi.github.io/cxx-abi/" target="_top">C++
869 ABI for Itanium</a>) and that is used by G++ and other compilers
870 as the de facto standard ABI on many common architectures (including x86).
871 G++ can also use the ARM architecture's EABI, for embedded
872 systems relying only on a <span class="quote">“<span class="quote">free-standing implementation</span>”</span> that
873 doesn't include (much of) the standard library, and the GNU EABI for
874 hosted implementations on ARM. Those ABIs cover low-level details
875 such as virtual function implementation, struct inheritance layout,
876 name mangling, and exception handling.
877 </p><p>
878 A useful C++ ABI must also incorporate many details of the standard
879 library implementation. For a C ABI, the layouts of a few structs
880 (such as <span class="type">FILE</span>, <span class="type">stat</span>, <span class="type">jmpbuf</span>,
881 and the like) and a few macros suffice.
882 For C++, the details include the complete set of names of functions
883 and types used, the offsets of class members and virtual functions,
884 and the actual definitions of all inlines. C++ exposes many more
885 library details to the caller than C does. It makes defining
886 a complete ABI a much bigger undertaking, and requires not just
887 documenting library implementation details, but carefully designing
888 those details so that future bug fixes and optimizations don't
889 force breaking the ABI.
890 </p><p>
891 There are ways to help isolate library implementation details from the
892 ABI, but they trade off against speed. Library details used in inner
893 loops (e.g., <code class="function">getchar</code>) must be exposed and frozen for
894 all time, but many others may reasonably be kept hidden from user code,
895 so they may later be changed. Deciding which, and implementing
896 the decisions, must happen before you can reasonably document a
897 candidate C++ ABI that encompasses the standard library.
898 </p></td></tr><tr class="question"><td align="left" valign="top"><a id="faq.size_equals_capacity"></a><a id="q-size_equals_capacity"></a><p><strong>7.8.</strong></p></td><td align="left" valign="top"><p>
899 How do I make <code class="code">std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size</code>?
900 </p></td></tr><tr class="answer"><td align="left" valign="top"><a id="a-size_equals_capacity"></a></td><td align="left" valign="top"><p>
901 Since C++11 just call the <code class="function">shrink_to_fit()</code> member
902 function.
903 </p><p>
904 Before C++11, the standard idiom for deallocating a
905 <code class="classname">vector&lt;T&gt;</code>'s
906 unused memory was to create a temporary copy of the vector and swap their
907 contents, e.g. for <code class="classname">vector&lt;T&gt; v</code>
908 </p><div class="literallayout"><p><br />
909      std::vector&lt;T&gt;(v).swap(v);<br />
910     </p></div><p>
911 The copy will take O(n) time and the swap is constant time.
912 </p><p>
913 See <a class="link" href="manual/strings.html#strings.string.shrink" title="Shrink to Fit">Shrink-to-fit
914 strings</a> for a similar solution for strings.
915 </p></td></tr></tbody></table></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> </td></tr><tr><td width="40%" align="left" valign="top"> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> </td></tr></table></div></body></html>