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