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