xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/doc/xml/faq.xml (revision 5dd36a3bc8bf2a9dec29ceb6349550414570c447)
1<book xmlns="http://docbook.org/ns/docbook" version="5.0">
2
3<article xml:id="faq" xreflabel="Frequently Asked Questions">
4<?dbhtml filename="faq.html"?>
5
6<info><title>Frequently Asked Questions</title>
7
8  <copyright>
9    <year>
10      2008-2014
11    </year>
12    <holder>
13      <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.fsf.org">FSF</link>
14    </holder>
15  </copyright>
16</info>
17
18<!-- FAQ starts here -->
19<qandaset xml:id="faq.faq">
20
21<!-- General Information -->
22<qandadiv xml:id="faq.info" xreflabel="General Information">
23
24<qandaentry xml:id="faq.what">
25  <question xml:id="faq.what.q">
26    <para>
27      What is libstdc++?
28    </para>
29  </question>
30  <answer xml:id="faq.what.a">
31    <para>
32     The GNU Standard C++ Library v3 is an ongoing project to
33     implement the ISO 14882 Standard C++ library as described in
34     clauses 17 through 30 and annex D.  For those who want to see
35     exactly how far the project has come, or just want the latest
36     bleeding-edge code, the up-to-date source is available over
37     anonymous SVN, and can be browsed over
38     the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/svn.html">web</link>.
39    </para>
40  </answer>
41</qandaentry>
42
43<qandaentry xml:id="faq.why">
44  <question xml:id="q-why">
45    <para>
46      Why should I use libstdc++?
47    </para>
48  </question>
49  <answer xml:id="a-why">
50    <para>
51    The completion of the initial ISO C++ standardization effort gave the C++
52    community a powerful set of reuseable tools in the form of the C++
53    Standard Library.  However, for several years C++ implementations were
54    (as the Draft Standard used to say) <quote>incomplet and
55    incorrekt</quote>, and many suffered from limitations of the compilers
56    that used them.
57    </para>
58    <para>
59    The GNU compiler collection
60    (<command>gcc</command>, <command>g++</command>, etc) is widely
61    considered to be one of the leading compilers in the world.  Its
62    development is overseen by the
63    <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/">GCC team</link>.  All of
64    the rapid development and near-legendary
65    <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/buildstat.html">portability</link>
66    that are the hallmarks of an open-source project are applied to libstdc++.
67    </para>
68    <para>
69    All of the standard classes and functions from C++98/C++03
70    (such as <classname>string</classname>,
71    <classname>vector&lt;&gt;</classname>, iostreams, algorithms etc.)
72    are freely available and atempt to be fully compliant.
73    Work is ongoing to complete support for the current revision of the
74    ISO C++ Standard.
75    </para>
76  </answer>
77</qandaentry>
78
79<qandaentry xml:id="faq.who">
80  <question xml:id="q-who">
81    <para>
82      Who's in charge of it?
83    </para>
84  </question>
85  <answer xml:id="a-who">
86    <para>
87     The libstdc++ project is contributed to by several developers
88     all over the world, in the same way as GCC or the Linux kernel.
89     The current maintainers are listed in the
90     <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>
91     file (look for "c++ runtime libs").
92    </para>
93    <para>
94    Development and discussion is held on the libstdc++ mailing
95    list.  Subscribing to the list, or searching the list
96    archives, is open to everyone.  You can read instructions for
97    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.
98    If you have questions, ideas, code, or are just curious, sign up!
99    </para>
100  </answer>
101</qandaentry>
102
103<qandaentry xml:id="faq.when">
104  <question xml:id="q-when">
105    <para>
106      When is libstdc++ going to be finished?
107    </para>
108  </question>
109  <answer xml:id="a-when">
110    <para>
111    Nathan Myers gave the best of all possible answers, responding to
112    a Usenet article asking this question: <emphasis>Sooner, if you
113    help.</emphasis>
114    </para>
115  </answer>
116</qandaentry>
117
118<qandaentry xml:id="faq.how">
119  <question xml:id="q-how">
120    <para>
121      How do I contribute to the effort?
122    </para>
123  </question>
124  <answer xml:id="a-how">
125    <para>
126    See the <link linkend="appendix.contrib">Contributing</link> section in
127    the manual. Subscribing to the mailing list (see above, or
128    the homepage) is a very good idea if you have something to
129    contribute, or if you have spare time and want to
130    help. Contributions don't have to be in the form of source code;
131    anybody who is willing to help write documentation, for example,
132    or has found a bug in code that we all thought was working and is
133    willing to provide details, is more than welcome!
134    </para>
135  </answer>
136</qandaentry>
137
138<qandaentry xml:id="faq.whereis_old">
139  <question xml:id="q-whereis_old">
140    <para>
141      What happened to the older libg++? I need that!
142    </para>
143  </question>
144  <answer xml:id="a-whereis_old">
145    <para>
146    The last libg++ README states
147    <quote>This package is considered obsolete and is no longer
148    being developed.</quote>
149    It should not be used for new projects, and won't even compile with
150    recent releases of GCC (or most other C++ compilers).
151    </para>
152    <para>
153    More information can be found in the
154    <link linkend="manual.appendix.porting.backwards">Backwards
155    Compatibility</link> section of the libstdc++ manual.
156    </para>
157  </answer>
158</qandaentry>
159
160<qandaentry xml:id="faq.more_questions">
161  <question xml:id="q-more_questions">
162    <para>
163      What if I have more questions?
164    </para>
165  </question>
166  <answer xml:id="a-more_questions">
167    <para>
168    If you have read the documentation, and your question remains
169    unanswered, then just ask the mailing list. At present, you do not
170    need to be subscribed to the list to send a message to it.  More
171    information is available on the homepage (including how to browse
172    the list archives); to send a message to the list,
173    use <email>libstdc++@gcc.gnu.org</email>.
174    </para>
175
176    <para>
177    If you have a question that you think should be included
178    here, or if you have a question <emphasis>about</emphasis> a question/answer
179    here, please send email to the libstdc++ mailing list, as above.
180    </para>
181  </answer>
182</qandaentry>
183
184</qandadiv>
185
186<!-- License -->
187<qandadiv xml:id="faq.license" xreflabel="License QA">
188
189
190<qandaentry xml:id="faq.license.what">
191  <question xml:id="q-license.what">
192    <para>
193      What are the license terms for libstdc++?
194    </para>
195  </question>
196  <answer xml:id="a-license.what">
197    <para>
198    See <link linkend="manual.intro.status.license">our license description</link>
199    for these and related questions.
200    </para>
201  </answer>
202</qandaentry>
203
204<qandaentry xml:id="faq.license.any_program">
205  <question xml:id="q-license.any_program">
206    <para>
207      So any program which uses libstdc++ falls under the GPL?
208    </para>
209  </question>
210  <answer xml:id="a-license.any_program">
211    <para>
212     No. The special exception permits use of the library in
213     proprietary applications.
214    </para>
215  </answer>
216</qandaentry>
217
218
219<qandaentry xml:id="faq.license.lgpl">
220  <question xml:id="q-license.lgpl">
221    <para>
222      How is that different from the GNU {Lesser,Library} GPL?
223    </para>
224  </question>
225  <answer xml:id="a-license.lgpl">
226    <para>
227      The LGPL requires that users be able to replace the LGPL code with a
228     modified version; this is trivial if the library in question is a C
229     shared library.  But there's no way to make that work with C++, where
230     much of the library consists of inline functions and templates, which
231     are expanded inside the code that uses the library.  So to allow people
232     to replace the library code, someone using the library would have to
233     distribute their own source, rendering the LGPL equivalent to the GPL.
234    </para>
235  </answer>
236</qandaentry>
237
238<qandaentry xml:id="faq.license.what_restrictions">
239  <question xml:id="q-license.what_restrictions">
240    <para>
241      I see. So, what restrictions are there on programs that use the library?
242    </para>
243  </question>
244  <answer xml:id="a-license.what_restrictions">
245    <para>
246      None.  We encourage such programs to be released as free software,
247     but we won't punish you or sue you if you choose otherwise.
248    </para>
249  </answer>
250</qandaentry>
251
252</qandadiv>
253
254<!-- Installation -->
255<qandadiv xml:id="faq.installation" xreflabel="Installation">
256
257
258<qandaentry xml:id="faq.how_to_install">
259  <question xml:id="q-how_to_install">
260    <para>How do I install libstdc++?
261    </para>
262  </question>
263  <answer xml:id="a-how_to_install">
264    <para>
265    Often libstdc++ comes pre-installed as an integral part of many
266    existing GNU/Linux and Unix systems, as well as many embedded
267    development tools. It may be necessary to install extra
268    development packages to get the headers, or the documentation, or
269    the source: please consult your vendor for details.
270    </para>
271    <para>
272    To build and install from the GNU GCC sources, please consult the
273    <link linkend="manual.intro.setup">setup
274    documentation</link> for detailed
275    instructions. You may wish to browse those files ahead
276    of time to get a feel for what's required.
277    </para>
278  </answer>
279</qandaentry>
280
281<qandaentry xml:id="faq.how_to_get_sources">
282  <question xml:id="q-how_to_get_sources">
283    <para>How does one get current libstdc++ sources?
284    </para>
285  </question>
286  <answer xml:id="a-how_to_get_sources">
287    <para>
288    Libstdc++ sources for all official releases can be obtained as
289    part of the GCC sources, available from various sites and
290    mirrors. A full <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/mirrors.html">list of
291    download sites</link> is provided on the main GCC site.
292    </para>
293    <para>
294    Current libstdc++ sources can always be checked out of the main
295    GCC source repository using the appropriate version control
296    tool. At this time, that tool
297    is <application>Subversion</application>.
298    </para>
299    <para>
300    <application>Subversion</application>, or <acronym>SVN</acronym>, is
301    one of several revision control packages.  It was selected for GNU
302    projects because it's free (speech), free (beer), and very high
303    quality.  The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://subversion.tigris.org"> Subversion
304    home page</link> has a better description.
305    </para>
306    <para>
307    The <quote>anonymous client checkout</quote> feature of SVN is
308    similar to anonymous FTP in that it allows anyone to retrieve
309    the latest libstdc++ sources.
310    </para>
311    <para>
312    For more information
313    see <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://gcc.gnu.org/svn.html"><acronym>SVN</acronym>
314    details</link>.
315    </para>
316  </answer>
317</qandaentry>
318
319<qandaentry xml:id="faq.how_to_test">
320  <question xml:id="q-how_to_test">
321    <para>How do I know if it works?
322    </para>
323  </question>
324  <answer xml:id="a-how_to_test">
325    <para>
326    Libstdc++ comes with its own validation testsuite, which includes
327    conformance testing, regression testing, ABI testing, and
328    performance testing. Please consult the
329    <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/install/test.html">testing
330    documentation</link> for GCC and
331    <link linkend="manual.intro.setup.test">Testing</link> in the libstdc++
332    manual for more details.
333    </para>
334    <para>
335    If you find bugs in the testsuite programs themselves, or if you
336    think of a new test program that should be added to the suite,
337    <emphasis>please</emphasis> write up your idea and send it to the list!
338    </para>
339  </answer>
340</qandaentry>
341
342<qandaentry xml:id="faq.how_to_set_paths">
343  <question xml:id="q-how_to_set_paths">
344    <para>How do I insure that the dynamically linked library will be found?
345    </para>
346  </question>
347  <answer xml:id="a-how_to_set_paths">
348    <para>
349    Depending on your platform and library version, the error message might
350    be similar to one of the following:
351    </para>
352
353    <screen>
354    ./a.out: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
355
356    /usr/libexec/ld-elf.so.1: Shared object "libstdc++.so.6" not found
357    </screen>
358
359    <para>
360    This doesn't mean that the shared library isn't installed, only
361    that the dynamic linker can't find it. When a dynamically-linked
362    executable is run the linker finds and loads the required shared
363    libraries by searching a pre-configured list of directories. If
364    the directory where you've installed libstdc++ is not in this list
365    then the libraries won't be found.
366    </para>
367
368    <para>
369    If you already have an older version of libstdc++ installed then the
370    error might look like one of the following instead:
371    </para>
372
373    <screen>
374    ./a.out: /usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.20' not found
375    ./a.out: /usr/lib/libstdc++.so.6: version `CXXABI_1.3.8' not found
376    </screen>
377
378    <para>
379    This means the linker found <filename>/usr/lib/libstdc++.so.6</filename>
380    but that library belongs to an older version of GCC than was used to
381    compile and link the program <filename>a.out</filename> (or some part
382    of it). The program depends on code defined in the newer libstdc++
383    that belongs to the newer version of GCC, so the linker must be told
384    how to find the newer libstdc++ shared library.
385    </para>
386
387    <para>
388    The simplest way to fix this is
389    to use the <envar>LD_LIBRARY_PATH</envar> environment variable,
390    which is a colon-separated list of directories in which the linker
391    will search for shared libraries:
392    </para>
393
394    <screen><command>
395    export LD_LIBRARY_PATH=${prefix}/lib:$LD_LIBRARY_PATH
396    </command></screen>
397
398    <para>
399    Here the shell variable <varname>${prefix}</varname> is assumed to contain
400    the directory prefix where GCC was installed to. The directory containing
401    the library might depend on whether you want the 32-bit or 64-bit copy
402    of the library, so for example would be
403    <filename class="directory">${prefix}/lib64</filename> on some systems.
404    The exact environment variable to use will depend on your
405    platform, e.g. <envar>DYLD_LIBRARY_PATH</envar> for Darwin,
406    <envar>LD_LIBRARY_PATH_32</envar>/<envar>LD_LIBRARY_PATH_64</envar>
407    for Solaris 32-/64-bit,
408    and <envar>SHLIB_PATH</envar> for HP-UX.
409    </para>
410    <para>
411    See the man pages for <command>ld</command>, <command>ldd</command>
412    and <command>ldconfig</command> for more information. The dynamic
413    linker has different names on different platforms but the man page
414    is usually called something such as <filename>ld.so</filename>,
415    <filename>rtld</filename> or <filename>dld.so</filename>.
416    </para>
417    <para>
418    Using <envar>LD_LIBRARY_PATH</envar> is not always the best solution,
419    <link linkend="manual.intro.using.linkage.dynamic">Finding Dynamic or Shared
420    Libraries</link> in the manual gives some alternatives.
421    </para>
422  </answer>
423</qandaentry>
424
425<qandaentry xml:id="faq.what_is_libsupcxx">
426  <question xml:id="q-what_is_libsupcxx">
427    <para>
428      What's libsupc++?
429    </para>
430  </question>
431  <answer xml:id="a-what_is_libsupcxx">
432    <para>
433      If the only functions from <filename class="libraryfile">libstdc++.a</filename>
434      which you need are language support functions (those listed in
435      <link linkend="std.support">clause 18</link> of the
436      standard, e.g., <function>new</function> and
437      <function>delete</function>), then try linking against
438      <filename class="libraryfile">libsupc++.a</filename>, which is a subset of
439      <filename class="libraryfile">libstdc++.a</filename>.  (Using <command>gcc</command>
440      instead of <command>g++</command> and explicitly linking in
441      <filename class="libraryfile">libsupc++.a</filename> via <option>-lsupc++</option>
442      for the final link step will do it).  This library contains only
443      those support routines, one per object file.  But if you are
444      using anything from the rest of the library, such as IOStreams
445      or vectors, then you'll still need pieces from
446      <filename class="libraryfile">libstdc++.a</filename>.
447    </para>
448  </answer>
449</qandaentry>
450
451<qandaentry xml:id="faq.size">
452  <question xml:id="q-size">
453    <para>
454      This library is HUGE!
455    </para>
456  </question>
457  <answer xml:id="a-size">
458    <para>
459    Usually the size of libraries on disk isn't noticeable.  When a
460    link editor (or simply <quote>linker</quote>) pulls things from a
461    static archive library, only the necessary object files are copied
462    into your executable, not the entire library.  Unfortunately, even
463    if you only need a single function or variable from an object file,
464    the entire object file is extracted.  (There's nothing unique to C++
465    or libstdc++ about this; it's just common behavior, given here
466    for background reasons.)
467    </para>
468    <para>
469    Some of the object files which make up
470    <filename class="libraryfile">libstdc++.a</filename> are rather large.
471    If you create a statically-linked executable with
472    <option>-static</option>, those large object files are suddenly part
473    of your executable.  Historically the best way around this was to
474    only place a very few functions (often only a single one) in each
475    source/object file; then extracting a single function is the same
476    as extracting a single <filename>.o</filename> file.  For libstdc++ this
477    is only possible to a certain extent; the object files in question contain
478    template classes and template functions, pre-instantiated, and
479    splitting those up causes severe maintenance headaches.
480    </para>
481    <para>
482    On supported platforms, libstdc++ takes advantage of garbage
483    collection in the GNU linker to get a result similar to separating
484    each symbol into a separate source and object files. On these platforms,
485    GNU ld can place each function and variable into its own
486    section in a <filename>.o</filename> file.  The GNU linker can then perform
487    garbage collection on unused sections; this reduces the situation to only
488    copying needed functions into the executable, as before, but all
489    happens automatically.
490    </para>
491  </answer>
492</qandaentry>
493
494</qandadiv>
495
496
497<!-- Platform-Specific Issues -->
498<qandadiv xml:id="faq.platform-specific" xreflabel="Platform-Specific Issues">
499
500
501<qandaentry xml:id="faq.other_compilers">
502  <question xml:id="q-other_compilers">
503    <para>
504      Can libstdc++ be used with non-GNU compilers?
505    </para>
506  </question>
507  <answer xml:id="a-other_compilers">
508    <para>
509    Perhaps.
510    </para>
511    <para>
512    Since the goal of ISO Standardization is for all C++
513    implementations to be able to share code, libstdc++ should be
514    usable under any ISO-compliant compiler, at least in theory.
515    </para>
516    <para>
517    However, the reality is that libstdc++ is targeted and optimized
518    for GCC/G++. This means that often libstdc++ uses specific,
519    non-standard features of G++ that are not present in older
520    versions of proprietary compilers. It may take as much as a year or two
521    after an official release of GCC that contains these features for
522    proprietary tools to support these constructs.
523    </para>
524    <para>
525    Recent versions of libstdc++ are known to work with the Clang compiler.
526    In the near past, specific released versions of libstdc++ have
527    been known to work with versions of the EDG C++ compiler, and
528    vendor-specific proprietary C++ compilers such as the Intel ICC
529    C++ compiler.
530    </para>
531
532  </answer>
533</qandaentry>
534
535<qandaentry xml:id="faq.solaris_long_long">
536  <question xml:id="q-solaris_long_long">
537    <para>
538      No '<type>long long</type>' type on Solaris?
539    </para>
540  </question>
541  <answer xml:id="a-solaris_long_long">
542    <para>
543    By default we try to support the C99 <type>long long</type> type.
544    This requires that certain functions from your C library be present.
545    </para>
546    <para>
547    Up through release 3.0.2 the platform-specific tests performed by
548    libstdc++ were too general, resulting in a conservative approach
549    to enabling the <type>long long</type> code paths. The most
550    commonly reported platform affected was Solaris.
551    </para>
552    <para>
553    This has been fixed for libstdc++ releases greater than 3.0.3.
554    </para>
555  </answer>
556</qandaentry>
557
558<qandaentry xml:id="faq.predefined">
559  <question xml:id="q-predefined">
560    <para>
561      <constant>_XOPEN_SOURCE</constant> and <constant>_GNU_SOURCE</constant> are always defined?
562    </para>
563  </question>
564  <answer xml:id="a-predefined">
565      <para>On Solaris, <command>g++</command> (but not <command>gcc</command>)
566         always defines the preprocessor macro
567	 <constant>_XOPEN_SOURCE</constant>.  On GNU/Linux, the same happens
568         with <constant>_GNU_SOURCE</constant>.  (This is not an exhaustive list;
569         other macros and other platforms are also affected.)
570      </para>
571      <para>These macros are typically used in C library headers, guarding new
572         versions of functions from their older versions.  The C++98 standard
573         library includes the C standard library, but it requires the C90
574         version, which for backwards-compatibility reasons is often not the
575         default for many vendors.
576      </para>
577      <para>More to the point, the C++ standard requires behavior which is only
578         available on certain platforms after certain symbols are defined.
579         Usually the issue involves I/O-related typedefs.  In order to
580         ensure correctness, the compiler simply predefines those symbols.
581      </para>
582      <para>Note that it's not enough to <literal>#define</literal> them only when the library is
583         being built (during installation).  Since we don't have an 'export'
584         keyword, much of the library exists as headers, which means that
585         the symbols must also be defined as your programs are parsed and
586         compiled.
587      </para>
588      <para>To see which symbols are defined, look for
589         <varname>CPLUSPLUS_CPP_SPEC</varname> in
590         the gcc config headers for your target (and try changing them to
591         see what happens when building complicated code).  You can also run
592         <command>g++ -E -dM - &lt; /dev/null"</command> to display
593         a list of predefined macros for any particular installation.
594      </para>
595      <para>This has been discussed on the mailing lists
596         <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/cgi-bin/htsearch?method=and&amp;format=builtin-long&amp;sort=score&amp;words=_XOPEN_SOURCE+Solaris">quite a bit</link>.
597      </para>
598      <para>This method is something of a wart.  We'd like to find a cleaner
599         solution, but nobody yet has contributed the time.
600      </para>
601
602  </answer>
603</qandaentry>
604
605<qandaentry xml:id="faq.darwin_ctype">
606  <question xml:id="q-darwin_ctype">
607    <para>
608      Mac OS X <filename class="headerfile">ctype.h</filename> is broken! How can I fix it?
609    </para>
610  </question>
611  <answer xml:id="a-darwin_ctype">
612      <note>
613         <para>This answer is old and probably no longer be relevant.</para>
614      </note>
615      <para>
616         This was a long-standing bug in the OS X support.  Fortunately, the
617         <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/gcc/2002-03/msg00817.html">patch</link>
618	 was quite simple, and well-known.
619      </para>
620
621  </answer>
622</qandaentry>
623
624<qandaentry xml:id="faq.threads_i386">
625  <question xml:id="q-threads_i386">
626    <para>
627      Threading is broken on i386?
628    </para>
629  </question>
630  <answer xml:id="a-threads_i386">
631      <note>
632         <para>This answer is old and probably no longer be relevant.</para>
633      </note>
634      <para>Support for atomic integer operations was broken on i386
635         platforms.  The assembly code accidentally used opcodes that are
636         only available on the i486 and later.  So if you configured GCC
637         to target, for example, i386-linux, but actually used the programs
638         on an i686, then you would encounter no problems.  Only when
639         actually running the code on a i386 will the problem appear.
640      </para>
641      <para>This is fixed in 3.2.2.
642      </para>
643
644  </answer>
645</qandaentry>
646
647<qandaentry xml:id="faq.atomic_mips">
648  <question xml:id="q-atomic_mips">
649    <para>
650      MIPS atomic operations
651    </para>
652  </question>
653  <answer xml:id="a-atomic_mips">
654    <note>
655      <para>This answer is old and probably no longer be relevant.</para>
656    </note>
657    <para>
658    The atomic locking routines for MIPS targets requires MIPS II
659    and later.  A patch went in just after the 3.3 release to
660    make mips* use the generic implementation instead.  You can also
661    configure for mipsel-elf as a workaround.
662    </para>
663    <para>
664    The mips*-*-linux* port continues to use the MIPS II routines, and more
665    work in this area is expected.
666    </para>
667  </answer>
668</qandaentry>
669
670<qandaentry xml:id="faq.linux_glibc">
671  <question xml:id="q-linux_glibc">
672    <para>
673      Recent GNU/Linux glibc required?
674    </para>
675  </question>
676  <answer xml:id="a-linux_glibc">
677      <para>When running on GNU/Linux, libstdc++ 3.2.1 (shared library version
678         5.0.1) and later uses localization and formatting code from the system
679         C library (glibc) version 2.2.5 which contains necessary bugfixes.
680         All GNU/Linux distros make more recent versions available now.
681         libstdc++ 4.6.0 and later require glibc 2.3 or later for this
682         localization and formatting code.
683      </para>
684      <para>The guideline is simple:  the more recent the C++ library, the
685         more recent the C library.  (This is also documented in the main
686         GCC installation instructions.)
687      </para>
688
689  </answer>
690</qandaentry>
691
692<qandaentry xml:id="faq.freebsd_wchar">
693  <question xml:id="q-freebsd_wchar">
694    <para>
695      Can't use wchar_t/wstring on FreeBSD
696    </para>
697  </question>
698  <answer xml:id="a-freebsd_wchar">
699    <note>
700      <para>This answer is old and probably no longer be relevant.</para>
701    </note>
702    <para>
703    Older versions of FreeBSD's C library do not have sufficient
704    support for wide character functions, and as a result the
705    libstdc++ configury decides that <type>wchar_t</type> support should be
706    disabled. In addition, the libstdc++ platform checks that
707    enabled <type>wchar_t</type> were quite strict, and not granular
708    enough to detect when the minimal support to
709    enable <type>wchar_t</type> and C++ library structures
710    like <classname>wstring</classname> were present. This impacted Solaris,
711    Darwin, and BSD variants, and is fixed in libstdc++ versions post 4.1.0.
712    </para>
713    <para>
714    </para>
715  </answer>
716</qandaentry>
717
718</qandadiv>
719
720
721<!-- Known Bugs -->
722<qandadiv xml:id="faq.known_bugs" xreflabel="Known Bugs">
723
724
725<qandaentry xml:id="faq.what_works">
726  <question xml:id="q-what_works">
727    <para>
728      What works already?
729    </para>
730  </question>
731  <answer xml:id="a-what_works">
732    <para>
733    Short answer: Pretty much everything <emphasis>works</emphasis>
734    except for some corner cases.  Support for localization
735    in <classname>locale</classname> may be incomplete on some non-GNU
736    platforms. Also dependent on the underlying platform is support
737    for <type>wchar_t</type> and <type>long long</type> specializations,
738    and details of thread support.
739    </para>
740    <para>
741    Long answer: See the implementation status pages for
742    <link linkend="status.iso.1998">C++98</link>,
743    <link linkend="status.iso.tr1">TR1</link>,
744    <link linkend="status.iso.2011">C++11</link>,
745    <link linkend="status.iso.2014">C++14</link>, and
746    <link linkend="status.iso.2017">C++17</link>.
747    </para>
748  </answer>
749</qandaentry>
750
751<qandaentry xml:id="faq.standard_bugs">
752  <question xml:id="q-standard_bugs">
753    <para>
754      Bugs in the ISO C++ language or library specification
755    </para>
756  </question>
757  <answer xml:id="a-standard_bugs">
758    <para>
759    Unfortunately, there are some.
760    </para>
761    <para>
762    For those people who are not part of the ISO Library Group
763    (i.e., nearly all of us needing to read this page in the first
764    place), a public list of the library defects is occasionally
765    published on <link xmlns:xlink="http://www.w3.org/1999/xlink"
766    xlink:href="http://www.open-std.org/jtc1/sc22/wg21/">the WG21
767    website</link>.
768    Many of these issues have resulted in code changes in libstdc++.
769    </para>
770    <para>
771    If you think you've discovered a new bug that is not listed,
772    please post a message describing your problem to the author of
773    the library issues list.
774    </para>
775  </answer>
776</qandaentry>
777
778<qandaentry xml:id="faq.compiler_bugs">
779  <question xml:id="q-compiler_bugs">
780    <para>
781      Bugs in the compiler (gcc/g++) and not libstdc++
782    </para>
783  </question>
784  <answer xml:id="a-compiler_bugs">
785    <para>
786    On occasion, the compiler is wrong. Please be advised that this
787    happens much less often than one would think, and avoid jumping to
788    conclusions.
789    </para>
790    <para>
791    First, examine the ISO C++ standard. Second, try another compiler
792    or an older version of the GNU compilers. Third, you can find more
793    information on the libstdc++ and the GCC mailing lists: search
794    these lists with terms describing your issue.
795    </para>
796    <para>
797    Before reporting a bug, please examine the
798    <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/bugs/">bugs database</link> with the
799    category set to <quote>g++</quote>.
800    </para>
801  </answer>
802</qandaentry>
803
804</qandadiv>
805
806<!-- Known Non-Bugs -->
807<qandadiv xml:id="faq.known_non-bugs" xreflabel="Known Non-Bugs">
808
809
810<qandaentry xml:id="faq.stream_reopening_fails">
811  <question xml:id="q-stream_reopening_fails">
812    <para>
813      Reopening a stream fails
814    </para>
815  </question>
816  <answer xml:id="a-stream_reopening_fails">
817    <para>
818    One of the most-reported non-bug reports. Executing a sequence like:
819    </para>
820
821    <programlisting>
822    #include &lt;fstream&gt;
823    ...
824    std::fstream  fs("a_file");
825    // .
826    // . do things with fs...
827    // .
828    fs.close();
829    fs.open("a_new_file");
830    </programlisting>
831
832    <para>
833    All operations on the re-opened <varname>fs</varname> will fail, or at
834    least act very strangely.  Yes, they often will, especially if
835    <varname>fs</varname> reached the EOF state on the previous file.  The
836    reason is that the state flags are <emphasis>not</emphasis> cleared
837    on a successful call to open().  The standard unfortunately did
838    not specify behavior in this case, and to everybody's great sorrow,
839    the <link linkend="manual.intro.status.bugs">proposed LWG resolution in
840      DR #22</link> is to leave the flags unchanged.  You must insert a call
841    to <function>fs.clear()</function> between the calls to close() and open(),
842    and then everything will work like we all expect it to work.
843    <emphasis>Update:</emphasis> for GCC 4.0 we implemented the resolution
844    of <link linkend="manual.intro.status.bugs">DR #409</link> and open()
845    now calls <function>clear()</function> on success!
846    </para>
847  </answer>
848</qandaentry>
849
850<qandaentry xml:id="faq.wefcxx_verbose">
851  <question xml:id="q-wefcxx_verbose">
852    <para>
853      -Weffc++ complains too much
854    </para>
855  </question>
856  <answer xml:id="a-wefcxx_verbose">
857    <para>
858    Many warnings are emitted when <option>-Weffc++</option> is used.  Making
859    libstdc++ <option>-Weffc++</option>-clean is not a goal of the project,
860    for a few reasons.  Mainly, that option tries to enforce
861    object-oriented programming, while the Standard Library isn't
862    necessarily trying to be OO.
863    </para>
864    <para>
865    We do, however, try to have libstdc++ sources as clean as possible. If
866    you see some simple changes that pacify <option>-Weffc++</option>
867    without other drawbacks, send us a patch.
868    </para>
869  </answer>
870</qandaentry>
871
872<qandaentry xml:id="faq.ambiguous_overloads">
873  <question xml:id="q-ambiguous_overloads">
874    <para>
875      Ambiguous overloads after including an old-style header
876    </para>
877  </question>
878  <answer xml:id="a-ambiguous_overloads">
879    <note>
880      <para>This answer is old and probably no longer be relevant.</para>
881    </note>
882    <para>
883    Another problem is the <literal>rel_ops</literal> namespace and the template
884    comparison operator functions contained therein.  If they become
885    visible in the same namespace as other comparison functions
886    (e.g., <quote>using</quote> them and the &lt;iterator&gt; header),
887    then you will suddenly be faced with huge numbers of ambiguity
888    errors.  This was discussed on the -v3 list; Nathan Myers
889    <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/ml/libstdc++/2001-01/msg00247.html">sums
890      things up here</link>.  The collisions with vector/string iterator
891    types have been fixed for 3.1.
892    </para>
893  </answer>
894</qandaentry>
895
896<qandaentry xml:id="faq.v2_headers">
897  <question xml:id="q-v2_headers">
898    <para>
899      The g++-3 headers are <emphasis>not ours</emphasis>
900    </para>
901  </question>
902  <answer xml:id="a-v2_headers">
903      <para>
904	If you are using headers in
905	<filename class="directory">${prefix}/include/g++-3</filename>, or if
906	the installed library's name looks like
907	<filename class="libraryfile">libstdc++-2.10.a</filename> or
908	<filename class="libraryfile">libstdc++-libc6-2.10.so</filename>, then
909	you are using the old libstdc++-v2 library, which is non-standard and
910	unmaintained.  Do not report problems with -v2 to the -v3
911	mailing list.
912      </para>
913      <para>
914	For GCC versions 3.0 and 3.1 the libstdc++ header files are installed in
915	<filename class="directory">${prefix}/include/g++-v3</filename>
916	(see the 'v'?).  Starting with version 3.2 the headers are installed in
917	<filename class="directory">${prefix}/include/c++/${version}</filename>
918	as this prevents headers from previous versions being found by mistake.
919      </para>
920
921  </answer>
922</qandaentry>
923
924<qandaentry xml:id="faq.boost_concept_checks">
925  <question xml:id="q-boost_concept_checks">
926    <para>
927      Errors about <emphasis>*Concept</emphasis> and
928      <emphasis>constraints</emphasis> in the STL
929    </para>
930  </question>
931  <answer xml:id="a-boost_concept_checks">
932    <para>
933    If you see compilation errors containing messages about
934    <errortext>foo Concept</errortext> and something to do with a
935    <errortext>constraints</errortext> member function, then most
936    likely you have violated one of the requirements for types used
937    during instantiation of template containers and functions.  For
938    example, EqualityComparableConcept appears if your types must be
939    comparable with == and you have not provided this capability (a
940    typo, or wrong visibility, or you just plain forgot, etc).
941    </para>
942    <para>
943    More information, including how to optionally enable/disable the
944    checks, is available in the
945    <link linkend="std.diagnostics.concept_checking">Diagnostics</link>.
946    chapter of the manual.
947    </para>
948  </answer>
949</qandaentry>
950
951<qandaentry xml:id="faq.dlopen_crash">
952  <question xml:id="q-dlopen_crash">
953    <para>
954      Program crashes when using library code in a
955      dynamically-loaded library
956    </para>
957  </question>
958  <answer xml:id="a-dlopen_crash">
959    <para>
960    If you are using the C++ library across dynamically-loaded
961    objects, make certain that you are passing the correct options
962    when compiling and linking:
963    </para>
964
965    <literallayout class="normal">
966    Compile your library components:
967    <command>g++ -fPIC -c a.cc</command>
968    <command>g++ -fPIC -c b.cc</command>
969    ...
970    <command>g++ -fPIC -c z.cc</command>
971
972    Create your library:
973    <command>g++ -fPIC -shared -rdynamic -o libfoo.so a.o b.o ... z.o</command>
974
975    Link the executable:
976    <command>g++ -fPIC -rdynamic -o foo ... -L. -lfoo -ldl</command>
977    </literallayout>
978  </answer>
979</qandaentry>
980
981<qandaentry xml:id="faq.memory_leaks">
982  <question xml:id="q-memory_leaks">
983    <para>
984      <quote>Memory leaks</quote> in containers
985    </para>
986  </question>
987  <answer xml:id="a-memory_leaks">
988    <para>
989    A few people have reported that the standard containers appear
990    to leak memory when tested with memory checkers such as
991    <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://valgrind.org/"><command>valgrind</command></link>.
992    Under some configurations the library's allocators keep free memory in a
993    pool for later reuse, rather than returning it to the OS.  Although
994    this memory is always reachable by the library and is never
995    lost, memory debugging tools can report it as a leak.  If you
996    want to test the library for memory leaks please read
997    <link linkend="debug.memory">Tips for memory leak hunting</link>
998    first.
999    </para>
1000  </answer>
1001</qandaentry>
1002
1003<qandaentry xml:id="faq.list_size_on">
1004  <question xml:id="q-list_size_on">
1005    <para>
1006      list::size() is O(n)!
1007    </para>
1008  </question>
1009  <answer xml:id="a-list_size_on">
1010    <para>
1011    See
1012    the <link linkend="std.containers">Containers</link>
1013    chapter.
1014    </para>
1015  </answer>
1016</qandaentry>
1017
1018<qandaentry xml:id="faq.easy_to_fix">
1019  <question xml:id="q-easy_to_fix">
1020    <para>
1021      Aw, that's easy to fix!
1022    </para>
1023  </question>
1024  <answer xml:id="a-easy_to_fix">
1025    <para>
1026    If you have found a bug in the library and you think you have
1027    a working fix, then send it in!  The main GCC site has a page
1028    on <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://gcc.gnu.org/contribute.html">submitting
1029    patches</link> that covers the procedure, but for libstdc++ you
1030    should also send the patch to our mailing list in addition to
1031    the GCC patches mailing list.  The libstdc++
1032    <link linkend="appendix.contrib">contributors' page</link>
1033    also talks about how to submit patches.
1034    </para>
1035    <para>
1036    In addition to the description, the patch, and the ChangeLog
1037    entry, it is a Good Thing if you can additionally create a small
1038    test program to test for the presence of the bug that your patch
1039    fixes.  Bugs have a way of being reintroduced; if an old bug
1040    creeps back in, it will be caught immediately by the testsuite -
1041    but only if such a test exists.
1042    </para>
1043  </answer>
1044</qandaentry>
1045
1046</qandadiv>
1047
1048
1049<!-- Miscellaneous -->
1050<qandadiv xml:id="faq.misc" xreflabel="Miscellaneous">
1051
1052
1053<qandaentry xml:id="faq.iterator_as_pod">
1054  <question xml:id="faq.iterator_as_pod_q">
1055    <para>
1056      string::iterator is not char*; vector&lt;T&gt;::iterator is not T*
1057    </para>
1058  </question>
1059  <answer xml:id="faq.iterator_as_pod_a">
1060    <para>
1061    If you have code that depends on container&lt;T&gt; iterators
1062    being implemented as pointer-to-T, your code is broken. It's
1063    considered a feature, not a bug, that libstdc++ points this out.
1064    </para>
1065    <para>
1066    While there are arguments for iterators to be implemented in
1067    that manner, A) they aren't very good ones in the long term,
1068    and B) they were never guaranteed by the Standard anyway.  The
1069    type-safety achieved by making iterators a real class rather
1070    than a typedef for <type>T*</type> outweighs nearly all opposing
1071    arguments.
1072    </para>
1073    <para>
1074    Code which does assume that a vector iterator <varname>i</varname>
1075    is a pointer can often be fixed by changing <varname>i</varname> in
1076    certain expressions to <varname>&amp;*i</varname>.  Future revisions
1077    of the Standard are expected to bless this usage for
1078    vector&lt;&gt; (but not for basic_string&lt;&gt;).
1079    </para>
1080  </answer>
1081</qandaentry>
1082
1083<qandaentry xml:id="faq.what_is_next">
1084  <question xml:id="q-what_is_next">
1085    <para>
1086      What's next after libstdc++?
1087    </para>
1088  </question>
1089  <answer xml:id="a-what_is_next">
1090      <para>
1091	Hopefully, not much.  The goal of libstdc++ is to produce a
1092	fully-compliant, fully-portable Standard Library.  After that,
1093	we're mostly done: there won't <emphasis>be</emphasis> any
1094	more compliance work to do.
1095      </para>
1096      <para>
1097	There is an effort underway to add significant extensions to
1098	the standard library specification.  The latest version of
1099	this effort is described in
1100         <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1101         The C++ Library Technical Report 1</link>.
1102      </para>
1103  </answer>
1104</qandaentry>
1105
1106<qandaentry xml:id="faq.sgi_stl">
1107  <question xml:id="q-sgi_stl">
1108    <para>
1109      What about the STL from SGI?
1110    </para>
1111  </question>
1112  <answer xml:id="a-sgi_stl">
1113    <para>
1114      The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/">STL from SGI</link>,
1115    version 3.3, was the final merge of the STL codebase.  The
1116    code in libstdc++ contains many fixes and changes, and
1117    the SGI code is no longer under active
1118    development.  We expect that no future merges will take place.
1119    </para>
1120    <para>
1121    In particular, <classname>string</classname> is not from SGI and makes no
1122    use of their "rope" class (which is included as an
1123    optional extension), nor is <classname>valarray</classname> and some others.
1124    Classes like <classname>vector&lt;&gt;</classname> are, but have been
1125    extensively modified.
1126    </para>
1127    <para>
1128    More information on the evolution of libstdc++ can be found at the
1129    <link linkend="appendix.porting.api">API
1130    evolution</link>
1131    and <link linkend="manual.appendix.porting.backwards">backwards
1132    compatibility</link> documentation.
1133    </para>
1134    <para>
1135    The <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.sgi.com/tech/stl/FAQ.html">FAQ</link>
1136    for SGI's STL is still recommended reading.
1137    </para>
1138  </answer>
1139</qandaentry>
1140
1141<qandaentry xml:id="faq.extensions_and_backwards_compat">
1142  <question xml:id="q-extensions_and_backwards_compat">
1143    <para>
1144      Extensions and Backward Compatibility
1145    </para>
1146  </question>
1147  <answer xml:id="a-extensions_and_backwards_compat">
1148    <para>
1149      See the <link linkend="manual.appendix.porting.backwards">link</link> on backwards compatibility and <link linkend="appendix.porting.api">link</link> on evolution.
1150    </para>
1151  </answer>
1152</qandaentry>
1153
1154<qandaentry xml:id="faq.tr1_support">
1155  <question xml:id="q-tr1_support">
1156    <para>
1157      Does libstdc++ support TR1?
1158    </para>
1159  </question>
1160  <answer xml:id="a-tr1_support">
1161    <para>
1162    Yes.
1163    </para>
1164    <para>
1165    The C++ Standard Library Technical Report adds many new features to
1166    the library.  The latest version of this effort is described in
1167    <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1836.pdf">
1168         Technical Report 1</link>.
1169    </para>
1170    <para>
1171    The implementation status of TR1 in libstdc++ can be tracked <link linkend="status.iso.tr1">on the TR1 status
1172    page</link>.
1173    </para>
1174  </answer>
1175</qandaentry>
1176
1177<qandaentry xml:id="faq.get_iso_cxx">
1178  <question xml:id="q-get_iso_cxx">
1179    <para>How do I get a copy of the ISO C++ Standard?
1180    </para>
1181  </question>
1182  <answer xml:id="a-get_iso_cxx">
1183    <para>
1184    Please refer to the <link linkend="appendix.contrib">Contributing</link>
1185    section in our manual.
1186    </para>
1187  </answer>
1188</qandaentry>
1189
1190<qandaentry xml:id="faq.what_is_abi">
1191  <question xml:id="q-what_is_abi">
1192    <para>
1193      What's an ABI and why is it so messy?
1194    </para>
1195  </question>
1196  <answer xml:id="a-what_is_abi">
1197    <para>
1198    <acronym>ABI</acronym> stands for <quote>Application Binary
1199    Interface</quote>.  Conventionally, it refers to a great
1200    mass of details about how arguments are arranged on the call
1201    stack and/or in registers, and how various types are arranged
1202    and padded in structs.  A single CPU design may suffer
1203    multiple ABIs designed by different development tool vendors
1204    who made different choices, or even by the same vendor for
1205    different target applications or compiler versions.  In ideal
1206    circumstances the CPU designer presents one ABI and all the
1207    OSes and compilers use it.  In practice every ABI omits
1208    details that compiler implementers (consciously or
1209    accidentally) must choose for themselves.
1210    </para>
1211    <para>
1212    That ABI definition suffices for compilers to generate code so a
1213    program can interact safely with an OS and its lowest-level libraries.
1214    Users usually want an ABI to encompass more detail, allowing libraries
1215    built with different compilers (or different releases of the same
1216    compiler!) to be linked together.  For C++, this includes many more
1217    details than for C, and most CPU designers (for good reasons elaborated
1218    below) have not stepped up to publish C++ ABIs.  Such an ABI has been
1219    defined for the Itanium architecture (see
1220    <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://itanium-cxx-abi.github.io/cxx-abi/">C++
1221    ABI for Itanium</link>) and that is used by G++ and other compilers
1222    as the de facto standard ABI on many common architectures (including x86).
1223    G++ can also use the ARM architecture's EABI, for embedded
1224    systems relying only on a <quote>free-standing implementation</quote> that
1225    doesn't include (much of) the standard library, and the GNU EABI for
1226    hosted implementations on ARM.  Those ABIs cover low-level details
1227    such as virtual function implementation, struct inheritance layout,
1228    name mangling, and exception handling.
1229   </para>
1230    <para>
1231    A useful C++ ABI must also incorporate many details of the standard
1232    library implementation.  For a C ABI, the layouts of a few structs
1233    (such as <type>FILE</type>, <type>stat</type>, <type>jmpbuf</type>,
1234    and the like) and a few macros suffice.
1235    For C++, the details include the complete set of names of functions
1236    and types used, the offsets of class members and virtual functions,
1237    and the actual definitions of all inlines.  C++ exposes many more
1238    library details to the caller than C does.  It makes defining
1239    a complete ABI a much bigger undertaking, and requires not just
1240    documenting library implementation details, but carefully designing
1241    those details so that future bug fixes and optimizations don't
1242    force breaking the ABI.
1243    </para>
1244    <para>
1245    There are ways to help isolate library implementation details from the
1246    ABI, but they trade off against speed.  Library details used in inner
1247    loops (e.g., <function>getchar</function>) must be exposed and frozen for
1248    all time, but many others may reasonably be kept hidden from user code,
1249    so they may later be changed.  Deciding which, and implementing
1250    the decisions, must happen before you can reasonably document a
1251    candidate C++ ABI that encompasses the standard library.
1252    </para>
1253  </answer>
1254</qandaentry>
1255
1256<qandaentry xml:id="faq.size_equals_capacity">
1257  <question xml:id="q-size_equals_capacity">
1258    <para>
1259      How do I make std::vector&lt;T&gt;::capacity() == std::vector&lt;T&gt;::size?
1260    </para>
1261  </question>
1262  <answer xml:id="a-size_equals_capacity">
1263    <para>
1264    The standard idiom for deallocating a <classname>vector&lt;T&gt;</classname>'s
1265    unused memory is to create a temporary copy of the vector and swap their
1266    contents, e.g. for <classname>vector&lt;T&gt; v</classname>
1267    </para>
1268    <literallayout class="normal">
1269     std::vector&lt;T&gt;(v).swap(v);
1270    </literallayout>
1271    <para>
1272    The copy will take O(n) time and the swap is constant time.
1273    </para>
1274    <para>
1275    See <link linkend="strings.string.shrink">Shrink-to-fit
1276    strings</link> for a similar solution for strings.
1277    </para>
1278  </answer>
1279</qandaentry>
1280
1281</qandadiv>
1282
1283
1284<!-- FAQ ends here -->
1285</qandaset>
1286
1287</article>
1288
1289</book>
1290