1 <book xmlns="http://docbook.org/ns/docbook" version="5.0">
3 <article xml:id="faq" xreflabel="Frequently Asked Questions">
4 <?dbhtml filename="faq.html"?>
6 <info><title>Frequently Asked Questions</title>
13 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.fsf.org">FSF</link>
18 <!-- FAQ starts here -->
19 <qandaset xml:id="faq.faq">
21 <!-- General Information -->
22 <qandadiv xml:id="faq.info" xreflabel="General Information">
24 <qandaentry xml:id="faq.what">
25 <question xml:id="faq.what.q">
30 <answer xml:id="faq.what.a">
32 The GNU Standard C++ Library v3 is an ongoing project to
33 implement the ISO 14882 C++ Standard Library as described in
34 clauses 20 through 33 and annex D (prior to the 2017 standard
35 the library clauses started with 17). For those who want to see
36 exactly how far the project has come, or just want the latest
37 bleeding-edge code, the up-to-date source is available over
38 anonymous SVN, and can be browsed over the
39 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/svn.html">web</link>.
43 N.B. The library is called libstdc++ <emphasis>not</emphasis> stdlibc++.
48 <qandaentry xml:id="faq.why">
49 <question xml:id="q-why">
51 Why should I use libstdc++?
54 <answer xml:id="a-why">
56 The completion of the initial ISO C++ standardization effort gave the C++
57 community a powerful set of reuseable tools in the form of the C++
58 Standard Library. However, for several years C++ implementations were
59 (as the Draft Standard used to say) <quote>incomplet and
60 incorrekt</quote>, and many suffered from limitations of the compilers
64 The GNU compiler collection
65 (<command>gcc</command>, <command>g++</command>, etc) is widely
66 considered to be one of the leading compilers in the world. Its
67 development is overseen by the
68 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/">GCC team</link>. All of
69 the rapid development and near-legendary
70 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/buildstat.html">portability</link>
71 that are the hallmarks of an open-source project are applied to libstdc++.
74 All of the standard classes and functions from C++98/C++03, C++11 and C++14
75 (such as <classname>string</classname>,
76 <classname>vector<></classname>, iostreams, algorithms etc.)
77 are freely available and attempt to be fully compliant.
78 Work is ongoing to complete support for the current revision of the
84 <qandaentry xml:id="faq.who">
85 <question xml:id="q-who">
87 Who's in charge of it?
90 <answer xml:id="a-who">
92 The libstdc++ project is contributed to by several developers
93 all over the world, in the same way as GCC or the Linux kernel.
94 The current maintainers are listed in the
95 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/viewcvs/gcc/trunk/MAINTAINERS?view=co"><filename>MAINTAINERS</filename></link>
96 file (look for "c++ runtime libs").
99 Development and discussion is held on the libstdc++ mailing
100 list. Subscribing to the list, or searching the list
101 archives, is open to everyone. You can read instructions for
102 doing so on the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/lists.html">GCC mailing lists</link> page.
103 If you have questions, ideas, code, or are just curious, sign up!
108 <qandaentry xml:id="faq.when">
109 <question xml:id="q-when">
111 When is libstdc++ going to be finished?
114 <answer xml:id="a-when">
116 Nathan Myers gave the best of all possible answers, responding to
117 a Usenet article asking this question: <emphasis>Sooner, if you
123 <qandaentry xml:id="faq.how">
124 <question xml:id="q-how">
126 How do I contribute to the effort?
129 <answer xml:id="a-how">
131 See the <link linkend="appendix.contrib">Contributing</link> section in
132 the manual. Subscribing to the mailing list (see above, or
133 the homepage) is a very good idea if you have something to
134 contribute, or if you have spare time and want to
135 help. Contributions don't have to be in the form of source code;
136 anybody who is willing to help write documentation, for example,
137 or has found a bug in code that we all thought was working and is
138 willing to provide details, is more than welcome!
143 <qandaentry xml:id="faq.whereis_old">
144 <question xml:id="q-whereis_old">
146 What happened to the older libg++? I need that!
149 <answer xml:id="a-whereis_old">
151 The last libg++ README states
152 <quote>This package is considered obsolete and is no longer
153 being developed.</quote>
154 It should not be used for new projects, and won't even compile with
155 recent releases of GCC (or most other C++ compilers).
158 More information can be found in the
159 <link linkend="manual.appendix.porting.backwards">Backwards
160 Compatibility</link> section of the libstdc++ manual.
165 <qandaentry xml:id="faq.more_questions">
166 <question xml:id="q-more_questions">
168 What if I have more questions?
171 <answer xml:id="a-more_questions">
173 If you have read the documentation, and your question remains
174 unanswered, then just ask the mailing list. At present, you do not
175 need to be subscribed to the list to send a message to it. More
176 information is available on the homepage (including how to browse
177 the list archives); to send a message to the list,
178 use <email>libstdc++@gcc.gnu.org</email>.
182 If you have a question that you think should be included
183 here, or if you have a question <emphasis>about</emphasis> a question/answer
184 here, please send email to the libstdc++ mailing list, as above.
192 <qandadiv xml:id="faq.license" xreflabel="License QA">
195 <qandaentry xml:id="faq.license.what">
196 <question xml:id="q-license.what">
198 What are the license terms for libstdc++?
201 <answer xml:id="a-license.what">
203 See <link linkend="manual.intro.status.license">our license description</link>
204 for these and related questions.
209 <qandaentry xml:id="faq.license.any_program">
210 <question xml:id="q-license.any_program">
212 So any program which uses libstdc++ falls under the GPL?
215 <answer xml:id="a-license.any_program">
217 No. The special exception permits use of the library in
218 proprietary applications.
224 <qandaentry xml:id="faq.license.lgpl">
225 <question xml:id="q-license.lgpl">
227 How is that different from the GNU {Lesser,Library} GPL?
230 <answer xml:id="a-license.lgpl">
232 The LGPL requires that users be able to replace the LGPL code with a
233 modified version; this is trivial if the library in question is a C
234 shared library. But there's no way to make that work with C++, where
235 much of the library consists of inline functions and templates, which
236 are expanded inside the code that uses the library. So to allow people
237 to replace the library code, someone using the library would have to
238 distribute their own source, rendering the LGPL equivalent to the GPL.
243 <qandaentry xml:id="faq.license.what_restrictions">
244 <question xml:id="q-license.what_restrictions">
246 I see. So, what restrictions are there on programs that use the library?
249 <answer xml:id="a-license.what_restrictions">
251 None. We encourage such programs to be released as free software,
252 but we won't punish you or sue you if you choose otherwise.
259 <!-- Installation -->
260 <qandadiv xml:id="faq.installation" xreflabel="Installation">
263 <qandaentry xml:id="faq.how_to_install">
264 <question xml:id="q-how_to_install">
265 <para>How do I install libstdc++?
268 <answer xml:id="a-how_to_install">
270 Often libstdc++ comes pre-installed as an integral part of many
271 existing GNU/Linux and Unix systems, as well as many embedded
272 development tools. It may be necessary to install extra
273 development packages to get the headers, or the documentation, or
274 the source: please consult your vendor for details.
277 To build and install from the GNU GCC sources, please consult the
278 <link linkend="manual.intro.setup">setup
279 documentation</link> for detailed
280 instructions. You may wish to browse those files ahead
281 of time to get a feel for what's required.
286 <qandaentry xml:id="faq.how_to_get_sources">
287 <question xml:id="q-how_to_get_sources">
288 <para>How does one get current libstdc++ sources?
291 <answer xml:id="a-how_to_get_sources">
293 Libstdc++ sources for all official releases can be obtained as
294 part of the GCC sources, available from various sites and
295 mirrors. A full <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/mirrors.html">list of
296 download sites</link> is provided on the main GCC site.
299 Current libstdc++ sources can always be checked out of the main
300 GCC source repository using the appropriate version control
301 tool. At this time, that tool
302 is <application>Subversion</application>.
305 <application>Subversion</application>, or <acronym>SVN</acronym>, is
306 one of several revision control packages. It was selected for GNU
307 projects because it's free (speech), free (beer), and very high
308 quality. The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://subversion.tigris.org"> Subversion
309 home page</link> has a better description.
312 The <quote>anonymous client checkout</quote> feature of SVN is
313 similar to anonymous FTP in that it allows anyone to retrieve
314 the latest libstdc++ sources.
318 see <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/svn.html"><acronym>SVN</acronym>
324 <qandaentry xml:id="faq.how_to_test">
325 <question xml:id="q-how_to_test">
326 <para>How do I know if it works?
329 <answer xml:id="a-how_to_test">
331 Libstdc++ comes with its own validation testsuite, which includes
332 conformance testing, regression testing, ABI testing, and
333 performance testing. Please consult the
334 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/test.html">testing
335 documentation</link> for GCC and
336 <link linkend="manual.intro.setup.test">Testing</link> in the libstdc++
337 manual for more details.
340 If you find bugs in the testsuite programs themselves, or if you
341 think of a new test program that should be added to the suite,
342 <emphasis>please</emphasis> write up your idea and send it to the list!
347 <qandaentry xml:id="faq.how_to_set_paths">
348 <question xml:id="q-how_to_set_paths">
349 <para>How do I insure that the dynamically linked library will be found?
352 <answer xml:id="a-how_to_set_paths">
354 Depending on your platform and library version, the error message might
355 be similar to one of the following:
359 ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
361 /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
365 This doesn't mean that the shared library isn't installed, only
366 that the dynamic linker can't find it. When a dynamically-linked
367 executable is run the linker finds and loads the required shared
368 libraries by searching a pre-configured list of directories. If
369 the directory where you've installed libstdc++ is not in this list
370 then the libraries won't be found.
374 If you already have an older version of libstdc++ installed then the
375 error might look like one of the following instead:
379 ./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found
380 ./a.out: /usr/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found
384 This means the linker found <filename>/usr/lib/libstdc++.so.6</filename>
385 but that library belongs to an older version of GCC than was used to
386 compile and link the program <filename>a.out</filename> (or some part
387 of it). The program depends on code defined in the newer libstdc++
388 that belongs to the newer version of GCC, so the linker must be told
389 how to find the newer libstdc++ shared library.
393 The simplest way to fix this is
394 to use the <envar>LD_LIBRARY_PATH</envar> environment variable,
395 which is a colon-separated list of directories in which the linker
396 will search for shared libraries:
400 export LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
404 Here the shell variable <varname>${prefix}</varname> is assumed to contain
405 the directory prefix where GCC was installed to. The directory containing
406 the library might depend on whether you want the 32-bit or 64-bit copy
407 of the library, so for example would be
408 <filename class="directory">${prefix}/lib64</filename> on some systems.
409 The exact environment variable to use will depend on your
410 platform, e.g. <envar>DYLD_LIBRARY_PATH</envar> for Darwin,
411 <envar>LD_LIBRARY_PATH_32</envar>/<envar>LD_LIBRARY_PATH_64</envar>
412 for Solaris 32-/64-bit,
413 and <envar>SHLIB_PATH</envar> for HP-UX.
416 See the man pages for <command>ld</command>, <command>ldd</command>
417 and <command>ldconfig</command> for more information. The dynamic
418 linker has different names on different platforms but the man page
419 is usually called something such as <filename>ld.so</filename>,
420 <filename>rtld</filename> or <filename>dld.so</filename>.
423 Using <envar>LD_LIBRARY_PATH</envar> is not always the best solution,
424 <link linkend="manual.intro.using.linkage.dynamic">Finding Dynamic or Shared
425 Libraries</link> in the manual gives some alternatives.
430 <qandaentry xml:id="faq.what_is_libsupcxx">
431 <question xml:id="q-what_is_libsupcxx">
436 <answer xml:id="a-what_is_libsupcxx">
438 If the only functions from <filename class="libraryfile">libstdc++.a</filename>
439 which you need are language support functions (those listed in
440 <link linkend="std.support">clause 18</link> of the
441 standard, e.g., <function>new</function> and
442 <function>delete</function>), then try linking against
443 <filename class="libraryfile">libsupc++.a</filename>, which is a subset of
444 <filename class="libraryfile">libstdc++.a</filename>. (Using <command>gcc</command>
445 instead of <command>g++</command> and explicitly linking in
446 <filename class="libraryfile">libsupc++.a</filename> via <option>-lsupc++</option>
447 for the final link step will do it). This library contains only
448 those support routines, one per object file. But if you are
449 using anything from the rest of the library, such as IOStreams
450 or vectors, then you'll still need pieces from
451 <filename class="libraryfile">libstdc++.a</filename>.
456 <qandaentry xml:id="faq.size">
457 <question xml:id="q-size">
459 This library is HUGE!
462 <answer xml:id="a-size">
464 Usually the size of libraries on disk isn't noticeable. When a
465 link editor (or simply <quote>linker</quote>) pulls things from a
466 static archive library, only the necessary object files are copied
467 into your executable, not the entire library. Unfortunately, even
468 if you only need a single function or variable from an object file,
469 the entire object file is extracted. (There's nothing unique to C++
470 or libstdc++ about this; it's just common behavior, given here
471 for background reasons.)
474 Some of the object files which make up
475 <filename class="libraryfile">libstdc++.a</filename> are rather large.
476 If you create a statically-linked executable with
477 <option>-static</option>, those large object files are suddenly part
478 of your executable. Historically the best way around this was to
479 only place a very few functions (often only a single one) in each
480 source/object file; then extracting a single function is the same
481 as extracting a single <filename>.o</filename> file. For libstdc++ this
482 is only possible to a certain extent; the object files in question contain
483 template classes and template functions, pre-instantiated, and
484 splitting those up causes severe maintenance headaches.
487 On supported platforms, libstdc++ takes advantage of garbage
488 collection in the GNU linker to get a result similar to separating
489 each symbol into a separate source and object files. On these platforms,
490 GNU ld can place each function and variable into its own
491 section in a <filename>.o</filename> file. The GNU linker can then perform
492 garbage collection on unused sections; this reduces the situation to only
493 copying needed functions into the executable, as before, but all
494 happens automatically.
502 <!-- Platform-Specific Issues -->
503 <qandadiv xml:id="faq.platform-specific" xreflabel="Platform-Specific Issues">
506 <qandaentry xml:id="faq.other_compilers">
507 <question xml:id="q-other_compilers">
509 Can libstdc++ be used with non-GNU compilers?
512 <answer xml:id="a-other_compilers">
517 Since the goal of ISO Standardization is for all C++
518 implementations to be able to share code, libstdc++ should be
519 usable under any ISO-compliant compiler, at least in theory.
522 However, the reality is that libstdc++ is targeted and optimized
523 for GCC/G++. This means that often libstdc++ uses specific,
524 non-standard features of G++ that are not present in older
525 versions of proprietary compilers. It may take as much as a year or two
526 after an official release of GCC that contains these features for
527 proprietary tools to support these constructs.
530 Recent versions of libstdc++ are known to work with the Clang compiler.
531 In the near past, specific released versions of libstdc++ have
532 been known to work with versions of the EDG C++ compiler, and
533 vendor-specific proprietary C++ compilers such as the Intel ICC
540 <qandaentry xml:id="faq.solaris_long_long">
541 <question xml:id="q-solaris_long_long">
543 No '<type>long long</type>' type on Solaris?
546 <answer xml:id="a-solaris_long_long">
548 <para>This answer is old and probably no longer be relevant.</para>
551 By default we try to support the C99 <type>long long</type> type.
552 This requires that certain functions from your C library be present.
555 Up through release 3.0.2 the platform-specific tests performed by
556 libstdc++ were too general, resulting in a conservative approach
557 to enabling the <type>long long</type> code paths. The most
558 commonly reported platform affected was Solaris.
561 This has been fixed for libstdc++ releases greater than 3.0.3.
566 <qandaentry xml:id="faq.predefined">
567 <question xml:id="q-predefined">
569 <constant>_XOPEN_SOURCE</constant> and <constant>_GNU_SOURCE</constant> are always defined?
572 <answer xml:id="a-predefined">
573 <para>On Solaris, <command>g++</command> (but not <command>gcc</command>)
574 always defines the preprocessor macro
575 <constant>_XOPEN_SOURCE</constant>. On GNU/Linux, the same happens
576 with <constant>_GNU_SOURCE</constant>. (This is not an exhaustive list;
577 other macros and other platforms are also affected.)
579 <para>These macros are typically used in C library headers, guarding new
580 versions of functions from their older versions. The C++98 standard
581 library includes the C standard library, but it requires the C90
582 version, which for backwards-compatibility reasons is often not the
583 default for many vendors.
585 <para>More to the point, the C++ standard requires behavior which is only
586 available on certain platforms after certain symbols are defined.
587 Usually the issue involves I/O-related typedefs. In order to
588 ensure correctness, the compiler simply predefines those symbols.
590 <para>Note that it's not enough to <literal>#define</literal> them only when the library is
591 being built (during installation). Since we don't have an 'export'
592 keyword, much of the library exists as headers, which means that
593 the symbols must also be defined as your programs are parsed and
596 <para>To see which symbols are defined, look for
597 <varname>CPLUSPLUS_CPP_SPEC</varname> in
598 the gcc config headers for your target (and try changing them to
599 see what happens when building complicated code). You can also run
600 <command>g++ -E -dM - < /dev/null"</command> to display
601 a list of predefined macros for any particular installation.
603 <para>This has been discussed on the mailing lists
604 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&format=builtin-long&sort=score&words=_XOPEN_SOURCE+Solaris">quite a bit</link>.
606 <para>This method is something of a wart. We'd like to find a cleaner
607 solution, but nobody yet has contributed the time.
613 <qandaentry xml:id="faq.darwin_ctype">
614 <question xml:id="q-darwin_ctype">
616 Mac OS X <filename class="headerfile">ctype.h</filename> is broken! How can I fix it?
619 <answer xml:id="a-darwin_ctype">
621 <para>This answer is old and probably no longer be relevant.</para>
624 This was a long-standing bug in the OS X support. Fortunately, the
625 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html">patch</link>
626 was quite simple, and well-known.
632 <qandaentry xml:id="faq.threads_i386">
633 <question xml:id="q-threads_i386">
635 Threading is broken on i386?
638 <answer xml:id="a-threads_i386">
640 <para>This answer is old and probably no longer be relevant.</para>
642 <para>Support for atomic integer operations was broken on i386
643 platforms. The assembly code accidentally used opcodes that are
644 only available on the i486 and later. So if you configured GCC
645 to target, for example, i386-linux, but actually used the programs
646 on an i686, then you would encounter no problems. Only when
647 actually running the code on a i386 will the problem appear.
649 <para>This is fixed in 3.2.2.
655 <qandaentry xml:id="faq.atomic_mips">
656 <question xml:id="q-atomic_mips">
658 MIPS atomic operations
661 <answer xml:id="a-atomic_mips">
663 <para>This answer is old and probably no longer be relevant.</para>
666 The atomic locking routines for MIPS targets requires MIPS II
667 and later. A patch went in just after the 3.3 release to
668 make mips* use the generic implementation instead. You can also
669 configure for mipsel-elf as a workaround.
672 The mips*-*-linux* port continues to use the MIPS II routines, and more
673 work in this area is expected.
678 <qandaentry xml:id="faq.linux_glibc">
679 <question xml:id="q-linux_glibc">
681 Recent GNU/Linux glibc required?
684 <answer xml:id="a-linux_glibc">
685 <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
686 5.0.1) and later uses localization and formatting code from the system
687 C library (glibc) version 2.2.5 which contains necessary bugfixes.
688 All GNU/Linux distros make more recent versions available now.
689 libstdc++ 4.6.0 and later require glibc 2.3 or later for this
690 localization and formatting code.
692 <para>The guideline is simple: the more recent the C++ library, the
693 more recent the C library. (This is also documented in the main
694 GCC installation instructions.)
700 <qandaentry xml:id="faq.freebsd_wchar">
701 <question xml:id="q-freebsd_wchar">
703 Can't use <type>wchar_t</type>/<classname>wstring</classname> on FreeBSD
706 <answer xml:id="a-freebsd_wchar">
708 <para>This answer is old and probably no longer be relevant.</para>
711 Older versions of FreeBSD's C library do not have sufficient
712 support for wide character functions, and as a result the
713 libstdc++ configury decides that <type>wchar_t</type> support should be
714 disabled. In addition, the libstdc++ platform checks that
715 enabled <type>wchar_t</type> were quite strict, and not granular
716 enough to detect when the minimal support to
717 enable <type>wchar_t</type> and C++ library structures
718 like <classname>wstring</classname> were present. This impacted Solaris,
719 Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
730 <qandadiv xml:id="faq.known_bugs" xreflabel="Known Bugs">
733 <qandaentry xml:id="faq.what_works">
734 <question xml:id="q-what_works">
739 <answer xml:id="a-what_works">
741 Short answer: Pretty much everything <emphasis>works</emphasis>
742 except for some corner cases. Support for localization
743 in <classname>locale</classname> may be incomplete on some non-GNU
744 platforms. Also dependent on the underlying platform is support
745 for <type>wchar_t</type> and <type>long
746 long</type> specializations, and details of thread support.
749 Long answer: See the implementation status pages for
750 <link linkend="status.iso.1998">C++98</link>,
751 <link linkend="status.iso.tr1">TR1</link>, and
752 <link linkend="status.iso.2011">C++11</link>.
753 <link linkend="status.iso.2014">C++14</link>.
758 <qandaentry xml:id="faq.standard_bugs">
759 <question xml:id="q-standard_bugs">
761 Bugs in the ISO C++ language or library specification
764 <answer xml:id="a-standard_bugs">
766 Unfortunately, there are some.
769 For those people who are not part of the ISO Library Group
770 (i.e., nearly all of us needing to read this page in the first
771 place), a public list of the library defects is occasionally
772 published on <link xmlns:xlink="http://www.w3.org/1999/xlink"
773 xlink:href="http://www.open-std.org/jtc1/sc22/wg21/">the WG21
775 Many of these issues have resulted in
776 <link linkend="manual.intro.status.bugs.iso">code changes in libstdc++</link>.
779 If you think you've discovered a new bug that is not listed,
780 please post a message describing your problem to the author of
781 the library issues list.
786 <qandaentry xml:id="faq.compiler_bugs">
787 <question xml:id="q-compiler_bugs">
789 Bugs in the compiler (gcc/g++) and not libstdc++
792 <answer xml:id="a-compiler_bugs">
794 On occasion, the compiler is wrong. Please be advised that this
795 happens much less often than one would think, and avoid jumping to
799 First, examine the ISO C++ standard. Second, try another compiler
800 or an older version of the GNU compilers. Third, you can find more
801 information on the libstdc++ and the GCC mailing lists: search
802 these lists with terms describing your issue.
805 Before reporting a bug, please examine the
806 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/bugs/">bugs database</link>, with the
807 component set to <quote>c++</quote>.
814 <!-- Known Non-Bugs -->
815 <qandadiv xml:id="faq.known_non-bugs" xreflabel="Known Non-Bugs">
818 <qandaentry xml:id="faq.stream_reopening_fails">
819 <question xml:id="q-stream_reopening_fails">
821 Reopening a stream fails
824 <answer xml:id="a-stream_reopening_fails">
826 <para>This answer is old and probably no longer be relevant.</para>
829 Prior to GCC 4.0 this was one of the most-reported non-bug reports.
830 Executing a sequence like this would fail:
834 #include <fstream>
836 std::fstream fs("a_file");
838 // . do things with fs...
841 fs.open("a_new_file");
845 All operations on the re-opened <varname>fs</varname> would fail, or at
846 least act very strangely, especially if <varname>fs</varname> reached the
847 EOF state on the previous file.
848 The original C++98 standard did not specify behavior in this case, and
849 the <link linkend="manual.bugs.dr22">resolution of DR #22</link> was to
850 leave the state flags unchanged on a successful call to
851 <function>open()</function>.
852 You had to insert a call to <function>fs.clear()</function> between the
853 calls to <function>close()</function> and <function>open()</function>,
854 and then everything will work as expected.
855 <emphasis>Update:</emphasis> For GCC 4.0 we implemented the resolution
856 of <link linkend="manual.bugs.dr409">DR #409</link> and
857 <function>open()</function>
858 now calls <function>clear()</function> on success.
863 <qandaentry xml:id="faq.wefcxx_verbose">
864 <question xml:id="q-wefcxx_verbose">
866 -Weffc++ complains too much
869 <answer xml:id="a-wefcxx_verbose">
871 Many warnings are emitted when <option>-Weffc++</option> is used. Making
872 libstdc++ <option>-Weffc++</option>-clean is not a goal of the project,
873 for a few reasons. Mainly, that option tries to enforce
874 object-oriented programming, while the Standard Library isn't
875 necessarily trying to be OO. The option also enforces outdated guidelines
876 from old editions of the books, and the advice isn't all relevant to
877 modern C++ (especially C++11 and later).
880 We do, however, try to have libstdc++ sources as clean as possible. If
881 you see some simple changes that pacify <option>-Weffc++</option>
882 without other drawbacks, send us a patch.
887 <qandaentry xml:id="faq.ambiguous_overloads">
888 <question xml:id="q-ambiguous_overloads">
890 Ambiguous overloads after including an old-style header
893 <answer xml:id="a-ambiguous_overloads">
895 Another problem is the <literal>rel_ops</literal> namespace and the template
896 comparison operator functions contained therein. If they become
897 visible in the same namespace as other comparison functions
898 (e.g., <quote>using</quote> them and the
899 <filename class="headerfile"><iterator></filename> header),
900 then you will suddenly be faced with huge numbers of ambiguity
901 errors. This was discussed on the mailing list; Nathan Myers
902 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html">sums
903 things up here</link>. The collisions with vector/string iterator
904 types have been fixed for 3.1.
909 <qandaentry xml:id="faq.v2_headers">
910 <question xml:id="q-v2_headers">
912 The g++-3 headers are <emphasis>not ours</emphasis>
915 <answer xml:id="a-v2_headers">
917 <para>This answer is old and probably no longer be relevant.</para>
920 If you are using headers in
921 <filename class="directory">${prefix}/include/g++-3</filename>, or if
922 the installed library's name looks like
923 <filename class="libraryfile">libstdc++-2.10.a</filename> or
924 <filename class="libraryfile">libstdc++-libc6-2.10.so</filename>, then
925 you are using the old libstdc++-v2 library, which is non-standard and
926 unmaintained. Do not report problems with -v2 to the -v3
930 For GCC versions 3.0 and 3.1 the libstdc++ header files are installed in
931 <filename class="directory">${prefix}/include/g++-v3</filename>
932 (see the 'v'?). Starting with version 3.2 the headers are installed in
933 <filename class="directory">${prefix}/include/c++/${version}</filename>
934 as this prevents headers from previous versions being found by mistake.
940 <qandaentry xml:id="faq.boost_concept_checks">
941 <question xml:id="q-boost_concept_checks">
943 Errors about <emphasis>*Concept</emphasis> and
944 <emphasis>constraints</emphasis> in the STL
947 <answer xml:id="a-boost_concept_checks">
949 If you see compilation errors containing messages about
950 <errortext>foo Concept</errortext> and something to do with a
951 <errortext>constraints</errortext> member function, then most
952 likely you have violated one of the requirements for types used
953 during instantiation of template containers and functions. For
954 example, EqualityComparableConcept appears if your types must be
955 comparable with == and you have not provided this capability (a
956 typo, or wrong visibility, or you just plain forgot, etc).
959 More information, including how to optionally enable/disable the
960 checks, is available in the
961 <link linkend="std.diagnostics.concept_checking">Diagnostics</link>.
962 chapter of the manual.
967 <qandaentry xml:id="faq.dlopen_crash">
968 <question xml:id="q-dlopen_crash">
970 Program crashes when using library code in a
971 dynamically-loaded library
974 <answer xml:id="a-dlopen_crash">
976 If you are using the C++ library across dynamically-loaded
977 objects, make certain that you are passing the correct options
978 when compiling and linking:
981 <literallayout class="normal">
982 Compile your library components:
983 <command>g++ -fPIC -c a.cc</command>
984 <command>g++ -fPIC -c b.cc</command>
986 <command>g++ -fPIC -c z.cc</command>
989 <command>g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o</command>
992 <command>g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl</command>
997 <qandaentry xml:id="faq.memory_leaks">
998 <question xml:id="q-memory_leaks">
1000 <quote>Memory leaks</quote> in containers
1003 <answer xml:id="a-memory_leaks">
1005 <para>This answer is old and probably no longer be relevant.</para>
1008 A few people have reported that the standard containers appear
1009 to leak memory when tested with memory checkers such as
1010 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://valgrind.org/"><command>valgrind</command></link>.
1011 Under some (non-default) configurations the library's allocators keep
1013 pool for later reuse, rather than returning it to the OS. Although
1014 this memory is always reachable by the library and is never
1015 lost, memory debugging tools can report it as a leak. If you
1016 want to test the library for memory leaks please read
1017 <link linkend="debug.memory">Tips for memory leak hunting</link>
1023 <qandaentry xml:id="faq.list_size_on">
1024 <question xml:id="q-list_size_on">
1026 <code>list::size()</code> is O(n)!
1029 <answer xml:id="a-list_size_on">
1032 the <link linkend="std.containers">Containers</link>
1038 <qandaentry xml:id="faq.easy_to_fix">
1039 <question xml:id="q-easy_to_fix">
1041 Aw, that's easy to fix!
1044 <answer xml:id="a-easy_to_fix">
1046 If you have found a bug in the library and you think you have
1047 a working fix, then send it in! The main GCC site has a page
1048 on <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/contribute.html">submitting
1049 patches</link> that covers the procedure, but for libstdc++ you
1050 should also send the patch to our mailing list in addition to
1051 the GCC patches mailing list. The libstdc++
1052 <link linkend="appendix.contrib">contributors' page</link>
1053 also talks about how to submit patches.
1056 In addition to the description, the patch, and the ChangeLog
1057 entry, it is a Good Thing if you can additionally create a small
1058 test program to test for the presence of the bug that your patch
1059 fixes. Bugs have a way of being reintroduced; if an old bug
1060 creeps back in, it will be caught immediately by the testsuite -
1061 but only if such a test exists.
1069 <!-- Miscellaneous -->
1070 <qandadiv xml:id="faq.misc" xreflabel="Miscellaneous">
1073 <qandaentry xml:id="faq.iterator_as_pod">
1074 <question xml:id="faq.iterator_as_pod_q">
1076 <classname>string::iterator</classname> is not <code>char*</code>;
1077 <classname>vector<T>::iterator</classname> is not <code>T*</code>
1080 <answer xml:id="faq.iterator_as_pod_a">
1082 If you have code that depends on container<T> iterators
1083 being implemented as pointer-to-T, your code is broken. It's
1084 considered a feature, not a bug, that libstdc++ points this out.
1087 While there are arguments for iterators to be implemented in
1088 that manner, A) they aren't very good ones in the long term,
1089 and B) they were never guaranteed by the Standard anyway. The
1090 type-safety achieved by making iterators a real class rather
1091 than a typedef for <type>T*</type> outweighs nearly all opposing
1095 Code which does assume that a vector/string iterator <varname>i</varname>
1096 is a pointer can often be fixed by changing <varname>i</varname> in
1097 certain expressions to <varname>&*i</varname>.
1102 <qandaentry xml:id="faq.what_is_next">
1103 <question xml:id="q-what_is_next">
1105 What's next after libstdc++?
1108 <answer xml:id="a-what_is_next">
1110 The goal of libstdc++ is to produce a
1111 fully-compliant, fully-portable Standard Library.
1112 While the C++ Standard continues to evolve the libstdc++ will
1113 continue to track it.
1118 <qandaentry xml:id="faq.sgi_stl">
1119 <question xml:id="q-sgi_stl">
1121 What about the STL from SGI?
1124 <answer xml:id="a-sgi_stl">
1126 The STL (Standard Template Library) was the inspiration for large chunks
1127 of the C++ Standard Library, but the terms are not interchangeable and
1128 they don't mean the same thing. The C++ Standard Library includes lots of
1129 things that didn't come from the STL, and some of them aren't even
1130 templates, such as <classname>std::locale</classname> and
1131 <classname>std::thread</classname>.
1134 Libstdc++-v3 incorporates a lot of code from
1135 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/">the SGI STL</link>
1136 (the final merge was from
1137 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/whats_new.html">release 3.3</link>).
1138 The code in libstdc++ contains many fixes and changes compared to the
1142 In particular, <classname>string</classname> is not from SGI and makes no
1143 use of their "rope" class (although that is included as an optional
1144 extension), neither is <classname>valarray</classname> nor some others.
1145 Classes like <classname>vector<></classname> were from SGI, but have
1146 been extensively modified.
1149 More information on the evolution of libstdc++ can be found at the
1150 <link linkend="appendix.porting.api">API
1152 and <link linkend="manual.appendix.porting.backwards">backwards
1153 compatibility</link> documentation.
1156 The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/FAQ.html">FAQ</link>
1157 for SGI's STL is still recommended reading.
1162 <qandaentry xml:id="faq.extensions_and_backwards_compat">
1163 <question xml:id="q-extensions_and_backwards_compat">
1165 Extensions and Backward Compatibility
1168 <answer xml:id="a-extensions_and_backwards_compat">
1170 See the <link linkend="manual.appendix.porting.backwards">link</link> on backwards compatibility and <link linkend="appendix.porting.api">link</link> on evolution.
1175 <qandaentry xml:id="faq.tr1_support">
1176 <question xml:id="q-tr1_support">
1178 Does libstdc++ support TR1?
1181 <answer xml:id="a-tr1_support">
1186 The C++ Standard Library
1187 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1188 Technical Report 1</link> added many new features to the library.
1191 The implementation status of TR1 in libstdc++ can be tracked
1192 <link linkend="status.iso.tr1">on the TR1 status page</link>.
1195 New code should probably not use TR1, because almost everything in it has
1196 been added to the main C++ Standard Library (usually with significant
1198 The TR1 implementation in libstdc++ is no longer actively maintained.
1203 <qandaentry xml:id="faq.get_iso_cxx">
1204 <question xml:id="q-get_iso_cxx">
1205 <para>How do I get a copy of the ISO C++ Standard?
1208 <answer xml:id="a-get_iso_cxx">
1210 Please refer to the <link linkend="appendix.contrib">Contributing</link>
1211 section in our manual.
1216 <qandaentry xml:id="faq.what_is_abi">
1217 <question xml:id="q-what_is_abi">
1219 What's an ABI and why is it so messy?
1222 <answer xml:id="a-what_is_abi">
1224 <acronym>ABI</acronym> stands for <quote>Application Binary
1225 Interface</quote>. Conventionally, it refers to a great
1226 mass of details about how arguments are arranged on the call
1227 stack and/or in registers, and how various types are arranged
1228 and padded in structs. A single CPU design may suffer
1229 multiple ABIs designed by different development tool vendors
1230 who made different choices, or even by the same vendor for
1231 different target applications or compiler versions. In ideal
1232 circumstances the CPU designer presents one ABI and all the
1233 OSes and compilers use it. In practice every ABI omits
1234 details that compiler implementers (consciously or
1235 accidentally) must choose for themselves.
1238 That ABI definition suffices for compilers to generate code so a
1239 program can interact safely with an OS and its lowest-level libraries.
1240 Users usually want an ABI to encompass more detail, allowing libraries
1241 built with different compilers (or different releases of the same
1242 compiler!) to be linked together. For C++, this includes many more
1243 details than for C, and most CPU designers (for good reasons elaborated
1244 below) have not stepped up to publish C++ ABIs. Such an ABI has been
1245 defined for the Itanium architecture (see
1246 <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://itanium-cxx-abi.github.io/cxx-abi/">C++
1247 ABI for Itanium</link>) and that is used by G++ and other compilers
1248 as the de facto standard ABI on many common architectures (including x86).
1249 G++ can also use the ARM architecture's EABI, for embedded
1250 systems relying only on a <quote>free-standing implementation</quote> that
1251 doesn't include (much of) the standard library, and the GNU EABI for
1252 hosted implementations on ARM. Those ABIs cover low-level details
1253 such as virtual function implementation, struct inheritance layout,
1254 name mangling, and exception handling.
1257 A useful C++ ABI must also incorporate many details of the standard
1258 library implementation. For a C ABI, the layouts of a few structs
1259 (such as <type>FILE</type>, <type>stat</type>, <type>jmpbuf</type>,
1260 and the like) and a few macros suffice.
1261 For C++, the details include the complete set of names of functions
1262 and types used, the offsets of class members and virtual functions,
1263 and the actual definitions of all inlines. C++ exposes many more
1264 library details to the caller than C does. It makes defining
1265 a complete ABI a much bigger undertaking, and requires not just
1266 documenting library implementation details, but carefully designing
1267 those details so that future bug fixes and optimizations don't
1268 force breaking the ABI.
1271 There are ways to help isolate library implementation details from the
1272 ABI, but they trade off against speed. Library details used in inner
1273 loops (e.g., <function>getchar</function>) must be exposed and frozen for
1274 all time, but many others may reasonably be kept hidden from user code,
1275 so they may later be changed. Deciding which, and implementing
1276 the decisions, must happen before you can reasonably document a
1277 candidate C++ ABI that encompasses the standard library.
1282 <qandaentry xml:id="faq.size_equals_capacity">
1283 <question xml:id="q-size_equals_capacity">
1285 How do I make <code>std::vector<T>::capacity() == std::vector<T>::size</code>?
1288 <answer xml:id="a-size_equals_capacity">
1290 Since C++11 just call the <function>shrink_to_fit()</function> member
1294 Before C++11, the standard idiom for deallocating a
1295 <classname>vector<T></classname>'s
1296 unused memory was to create a temporary copy of the vector and swap their
1297 contents, e.g. for <classname>vector<T> v</classname>
1299 <literallayout class="normal">
1300 std::vector<T>(v).swap(v);
1303 The copy will take O(n) time and the swap is constant time.
1306 See <link linkend="strings.string.shrink">Shrink-to-fit
1307 strings</link> for a similar solution for strings.
1315 <!-- FAQ ends here -->