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