2 GCC Frequently Asked Questions
4 The latest version of this document is always available at
5 [1]http://gcc.gnu.org/faq.html.
7 This FAQ tries to answer specific questions concerning GCC. For
8 general information regarding C, C++, resp. Fortran please check the
9 [2]comp.lang.c FAQ, [3]comp.std.c++ FAQ, and the [4]Fortran
12 Other GCC-related FAQs: [5]libstdc++-v3, and [6]GCJ.
13 _________________________________________________________________
17 1. [7]General information
18 1. [8]What is an open development model?
19 2. [9]How do I get a bug fixed or a feature added?
20 3. [10]Does GCC work on my platform?
22 1. [12]How to install multiple versions of GCC
23 2. [13]Dynamic linker is unable to find GCC libraries
24 3. [14]libstdc++/libio tests fail badly with --enable-shared
25 4. [15]GCC can not find GNU as/GNU ld
26 5. [16]cpp: Usage:... Error
27 6. [17]Optimizing the compiler itself
28 7. [18]Why does libiconv get linked into jc1 on Solaris?
29 3. [19]Testsuite problems
30 1. [20]How do I pass flags like -fnew-abi to the testsuite?
31 2. [21]How can I run the test suite with multiple options?
33 1. [23]Friend Templates
34 2. [24]dynamic_cast, throw, typeid don't work with shared
36 3. [25]Why do I need autoconf, bison, xgettext, automake, etc?
37 4. [26]Why can't I build a shared library?
38 5. [27]When building C++, the linker says my constructors,
39 destructors or virtual tables are undefined, but I defined
41 6. [28]Will GCC someday include an incremental linker?
42 _________________________________________________________________
46 What is an open development model?
48 We are using a bazaar style [29][1] approach to GCC development: we
49 make snapshots publicly available to anyone who wants to try them; we
50 welcome anyone to join the development mailing list. All of the
51 discussions on the development mailing list are available via the web.
52 We're going to be making releases with a much higher frequency than
53 they have been made in the past.
55 In addition to weekly snapshots of the GCC development sources, we
56 have the sources readable from an SVN server by anyone. Furthermore we
57 are using SVN to allow maintainers write access to the sources.
59 There have been many potential GCC developers who were not able to
60 participate in GCC development in the past. We want these people to
61 help in any way they can; we ultimately want GCC to be the best
62 compiler in the world.
64 A compiler is a complicated piece of software, there will still be
65 strong central maintainers who will reject patches, who will demand
66 documentation of implementations, and who will keep the level of
67 quality as high as it is today. Code that could use wider testing may
68 be integrated--code that is simply ill-conceived won't be.
70 GCC is not the first piece of software to use this open development
71 process; FreeBSD, the Emacs lisp repository, and the Linux kernel are
72 a few examples of the bazaar style of development.
74 With GCC, we are adding new features and optimizations at a rate that
75 has not been done since the creation of gcc2; these additions
76 inevitably have a temporarily destabilizing effect. With the help of
77 developers working together with this bazaar style development, the
78 resulting stability and quality levels will be better than we've had
81 [1] We've been discussing different development models a lot over
82 the past few months. The paper which started all of this introduced
83 two terms: A cathedral development model versus a bazaar
84 development model. The paper is written by Eric S. Raymond, it is
85 called ``The Cathedral and the Bazaar''. The paper is a useful
86 starting point for discussions.
87 _________________________________________________________________
89 How do I get a bug fixed or a feature added?
91 There are lots of ways to get something fixed. The list below may be
92 incomplete, but it covers many of the common cases. These are listed
93 roughly in order of decreasing difficulty for the average GCC user,
94 meaning someone who is not skilled in the internals of GCC, and where
95 difficulty is measured in terms of the time required to fix the bug.
96 No alternative is better than any other; each has its benefits and
98 * Fix it yourself. This alternative will probably bring results, if
99 you work hard enough, but will probably take a lot of time, and,
100 depending on the quality of your work and the perceived benefits
101 of your changes, your code may or may not ever make it into an
102 official release of GCC.
103 * [30]Report the problem to the GCC bug tracking system and hope
104 that someone will be kind enough to fix it for you. While this is
105 certainly possible, and often happens, there is no guarantee that
106 it will. You should not expect the same response from this method
107 that you would see from a commercial support organization since
108 the people who read GCC bug reports, if they choose to help you,
109 will be volunteering their time.
110 * Hire someone to fix it for you. There are various companies and
111 individuals providing support for GCC. This alternative costs
112 money, but is relatively likely to get results.
113 _________________________________________________________________
115 Does GCC work on my platform?
117 The host/target specific installation notes for GCC include
118 information about known problems with installing or using GCC on
119 particular platforms. These are included in the sources for a release
120 in INSTALL/specific.html, and the [31]latest version is always
121 available at the GCC web site. Reports of [32]successful builds for
122 several versions of GCC are also available at the web site.
123 _________________________________________________________________
127 How to install multiple versions of GCC
129 It may be desirable to install multiple versions of the compiler on
130 the same system. This can be done by using different prefix paths at
131 configure time and a few symlinks.
133 Basically, configure the two compilers with different --prefix
134 options, then build and install each compiler. Assume you want "gcc"
135 to be the latest compiler and available in /usr/local/bin; also assume
136 that you want "gcc2" to be the older gcc2 compiler and also available
139 The easiest way to do this is to configure the new GCC with
140 --prefix=/usr/local/gcc and the older gcc2 with
141 --prefix=/usr/local/gcc2. Build and install both compilers. Then make
142 a symlink from /usr/local/bin/gcc to /usr/local/gcc/bin/gcc and from
143 /usr/local/bin/gcc2 to /usr/local/gcc2/bin/gcc. Create similar links
144 for the "g++", "c++" and "g77" compiler drivers.
146 An alternative to using symlinks is to configure with a
147 --program-transform-name option. This option specifies a sed command
148 to process installed program names with. Using it you can, for
149 instance, have all the new GCC programs installed as "new-gcc" and the
150 like. You will still have to specify different --prefix options for
151 new GCC and old GCC, because it is only the executable program names
152 that are transformed. The difference is that you (as administrator) do
153 not have to set up symlinks, but must specify additional directories
154 in your (as a user) PATH. A complication with --program-transform-name
155 is that the sed command invariably contains characters significant to
156 the shell, and these have to be escaped correctly, also it is not
157 possible to use "^" or "$" in the command. Here is the option to
158 prefix "new-" to the new GCC installed programs:
160 --program-transform-name='s,\\\\(.*\\\\),new-\\\\1,'
162 With the above --prefix option, that will install the new GCC programs
163 into /usr/local/gcc/bin with names prefixed by "new-". You can use
164 --program-transform-name if you have multiple versions of GCC, and
165 wish to be sure about which version you are invoking.
167 If you use --prefix, GCC may have difficulty locating a GNU assembler
168 or linker on your system, [33]GCC can not find GNU as/GNU ld explains
169 how to deal with this.
171 Another option that may be easier is to use the --program-prefix= or
172 --program-suffix= options to configure. So if you're installing GCC
173 2.95.2 and don't want to disturb the current version of GCC in
174 /usr/local/bin/, you could do
176 configure --program-suffix=-2.95.2 <other configure options>
178 This should result in GCC being installed as /usr/local/bin/gcc-2.95.2
179 instead of /usr/local/bin/gcc.
180 _________________________________________________________________
182 Dynamic linker is unable to find GCC libraries
184 This problem manifests itself by programs not finding shared libraries
185 they depend on when the programs are started. Note this problem often
186 manifests itself with failures in the libio/libstdc++ tests after
187 configuring with --enable-shared and building GCC.
189 GCC does not specify a runpath so that the dynamic linker can find
190 dynamic libraries at runtime.
192 The short explanation is that if you always pass a -R option to the
193 linker, then your programs become dependent on directories which may
194 be NFS mounted, and programs may hang unnecessarily when an NFS server
197 The problem is not programs that do require the directories; those
198 programs are going to hang no matter what you do. The problem is
199 programs that do not require the directories.
201 SunOS effectively always passed a -R option for every -L option; this
202 was a bad idea, and so it was removed for Solaris. We should not
205 However, if you feel you really need such an option to be passed
206 automatically to the linker, you may add it to the GCC specs file.
207 This file can be found in the same directory that contains cc1 (run
208 gcc -print-prog-name=cc1 to find it). You may add linker flags such as
209 -R or -rpath, depending on platform and linker, to the *link or *lib
212 Another alternative is to install a wrapper script around gcc, g++ or
213 ld that adds the appropriate directory to the environment variable
214 LD_RUN_PATH or equivalent (again, it's platform-dependent).
216 Yet another option, that works on a few platforms, is to hard-code the
217 full pathname of the library into its soname. This can only be
218 accomplished by modifying the appropriate .ml file within
219 libstdc++/config (and also libg++/config, if you are building libg++),
220 so that $(libdir)/ appears just before the library name in -soname or
222 _________________________________________________________________
224 GCC can not find GNU as/GNU ld
226 GCC searches the PATH for an assembler and a loader, but it only does
227 so after searching a directory list hard-coded in the GCC executables.
228 Since, on most platforms, the hard-coded list includes directories in
229 which the system assembler and loader can be found, you may have to
230 take one of the following actions to arrange that GCC uses the GNU
231 versions of those programs.
233 To ensure that GCC finds the GNU assembler (the GNU loader), which are
234 required by [34]some configurations, you should configure these with
235 the same --prefix option as you used for GCC. Then build & install GNU
236 as (GNU ld) and proceed with building GCC.
238 Another alternative is to create links to GNU as and ld in any of the
239 directories printed by the command `gcc -print-search-dirs | grep
240 '^programs:''. The link to `ld' should be named `real-ld' if `ld'
241 already exists. If such links do not exist while you're compiling GCC,
242 you may have to create them in the build directories too, within the
243 gcc directory and in all the gcc/stage* subdirectories.
245 GCC 2.95 allows you to specify the full pathname of the assembler and
246 the linker to use. The configure flags are `--with-as=/path/to/as' and
247 `--with-ld=/path/to/ld'. GCC will try to use these pathnames before
248 looking for `as' or `(real-)ld' in the standard search dirs. If, at
249 configure-time, the specified programs are found to be GNU utilities,
250 `--with-gnu-as' and `--with-gnu-ld' need not be used; these flags will
251 be auto-detected. One drawback of this option is that it won't allow
252 you to override the search path for assembler and linker with
253 command-line options -B/path/ if the specified filenames exist.
254 _________________________________________________________________
258 If you get an error like this when building GCC (particularly when
259 building __mulsi3), then you likely have a problem with your
260 environment variables.
261 cpp: Usage: /usr/lib/gcc-lib/i586-unknown-linux-gnulibc1/2.7.2.3/cpp
262 [switches] input output
264 First look for an explicit '.' in either LIBRARY_PATH or
265 GCC_EXEC_PREFIX from your environment. If you do not find an explicit
266 '.', look for an empty pathname in those variables. Note that ':' at
267 either the start or end of these variables is an implicit '.' and will
270 Also note '::' in these paths will also cause similar problems.
271 _________________________________________________________________
273 Optimizing the compiler itself
275 If you want to test a particular optimization option, it's useful to
276 try bootstrapping the compiler with that option turned on. For
277 example, to test the -fssa option, you could bootstrap like this:
278 make BOOT_CFLAGS="-O2 -fssa" bootstrap
279 _________________________________________________________________
281 Why does libiconv get linked into jc1 on Solaris?
283 The Java front end requires iconv. If the compiler used to bootstrap
284 GCC finds libiconv (because the GNU version of libiconv has been
285 installed in the same prefix as the bootstrap compiler), but the newly
286 built GCC does not find the library (because it will be installed with
287 a different prefix), then a link-time error will occur when building
288 jc1. This problem does not show up so often on platforms that have
289 libiconv in a default location (like /usr/lib) because then both
290 compilers can find a library named libiconv, even though it is a
293 Using --disable-nls at configure-time does not prevent this problem
294 because jc1 uses iconv even in that case. Solutions include
295 temporarily removing the GNU libiconv, copying it to a default
296 location such as /usr/lib/, and using --enable-languages at
297 configure-time to disable Java.
298 _________________________________________________________________
302 How do I pass flags like -fnew-abi to the testsuite?
304 If you invoke runtest directly, you can use the --tool_opts option,
306 runtest --tool_opts "-fnew-abi -fno-honor-std" <other options>
308 Or, if you use make check you can use the make variable RUNTESTFLAGS,
310 make RUNTESTFLAGS="--tool_opts '-fnew-abi -fno-honor-std'" check-g++
311 _________________________________________________________________
313 How can I run the test suite with multiple options?
315 If you invoke runtest directly, you can use the --target_board option,
317 runtest --target_board "unix{-fPIC,-fpic,}" <other options>
319 Or, if you use make check you can use the make variable RUNTESTFLAGS,
321 make RUNTESTFLAGS="--target_board 'unix{-fPIC,-fpic,}'" check-gcc
323 Either of these examples will run the tests three times. Once with
324 -fPIC, once with -fpic, and once with no additional flags.
326 This technique is particularly useful on multilibbed targets.
327 _________________________________________________________________
333 In order to make a specialization of a template function a friend of a
334 (possibly template) class, you must explicitly state that the friend
335 function is a template, by appending angle brackets to its name, and
336 this template function must have been declared already. Here's an
338 template <typename T> class foo {
339 friend void bar(foo<T>);
342 The above declaration declares a non-template function named bar, so
343 it must be explicitly defined for each specialization of foo. A
344 template definition of bar won't do, because it is unrelated with the
345 non-template declaration above. So you'd have to end up writing:
346 void bar(foo<int>) { /* ... */ }
347 void bar(foo<void>) { /* ... */ }
349 If you meant bar to be a template function, you should have
350 forward-declared it as follows. Note that, since the template function
351 declaration refers to the template class, the template class must be
352 forward-declared too:
353 template <typename T>
356 template <typename T>
359 template <typename T>
361 friend void bar<>(foo<T>);
364 template <typename T>
365 void bar(foo<T>) { /* ... */ }
367 In this case, the template argument list could be left empty, because
368 it can be implicitly deduced from the function arguments, but the
369 angle brackets must be present, otherwise the declaration will be
370 taken as a non-template function. Furthermore, in some cases, you may
371 have to explicitly specify the template arguments, to remove
374 An error in the last public comment draft of the ANSI/ISO C++ Standard
375 and the fact that previous releases of GCC would accept such friend
376 declarations as template declarations has led people to believe that
377 the forward declaration was not necessary, but, according to the final
378 version of the Standard, it is.
379 _________________________________________________________________
381 dynamic_cast, throw, typeid don't work with shared libraries
383 The new C++ ABI in the GCC 3.0 series uses address comparisons, rather
384 than string compares, to determine type equality. This leads to better
385 performance. Like other objects that have to be present in the final
386 executable, these std::type_info objects have what is called vague
387 linkage because they are not tightly bound to any one particular
388 translation unit (object file). The compiler has to emit them in any
389 translation unit that requires their presence, and then rely on the
390 linking and loading process to make sure that only one of them is
391 active in the final executable. With static linking all of these
392 symbols are resolved at link time, but with dynamic linking, further
393 resolution occurs at load time. You have to ensure that objects within
394 a shared library are resolved against objects in the executable and
395 other shared libraries.
396 * For a program which is linked against a shared library, no
397 additional precautions are needed.
398 * You cannot create a shared library with the "-Bsymbolic" option,
399 as that prevents the resolution described above.
400 * If you use dlopen to explicitly load code from a shared library,
401 you must do several things. First, export global symbols from the
402 executable by linking it with the "-E" flag (you will have to
403 specify this as "-Wl,-E" if you are invoking the linker in the
404 usual manner from the compiler driver, g++). You must also make
405 the external symbols in the loaded library available for
406 subsequent libraries by providing the RTLD_GLOBAL flag to dlopen.
407 The symbol resolution can be immediate or lazy.
409 Template instantiations are another, user visible, case of objects
410 with vague linkage, which needs similar resolution. If you do not take
411 the above precautions, you may discover that a template instantiation
412 with the same argument list, but instantiated in multiple translation
413 units, has several addresses, depending in which translation unit the
414 address is taken. (This is not an exhaustive list of the kind of
415 objects which have vague linkage and are expected to be resolved
416 during linking & loading.)
418 If you are worried about different objects with the same name
419 colliding during the linking or loading process, then you should use
420 namespaces to disambiguate them. Giving distinct objects with global
421 linkage the same name is a violation of the One Definition Rule (ODR)
424 For more details about the way that GCC implements these and other C++
425 features, please read the [35]ABI specification. Note the
426 std::type_info objects which must be resolved all begin with "_ZTS".
427 Refer to ld's documentation for a description of the "-E" &
429 _________________________________________________________________
431 Why do I need autoconf, bison, xgettext, automake, etc?
433 If you're using diffs up dated from one snapshot to the next, or if
434 you're using the SVN repository, you may need several additional
435 programs to build GCC.
437 These include, but are not necessarily limited to autoconf, automake,
440 This is necessary because neither diff nor cvs keep timestamps
441 correct. This causes problems for generated files as "make" may think
442 those generated files are out of date and try to regenerate them.
444 An easy way to work around this problem is to use the gcc_update
445 script in the contrib subdirectory of GCC, which handles this
446 transparently without requiring installation of any additional tools.
448 When building from diffs or SVN or if you modified some sources, you
449 may also need to obtain development versions of some GNU tools, as the
450 production versions do not necessarily handle all features needed to
453 In general, the current versions of these tools from
454 [36]ftp://ftp.gnu.org/gnu/ will work. At present, Autoconf 2.50 is not
455 supported, and you will need to use Autoconf 2.13; work is in progress
456 to fix this problem. Also look at
457 [37]ftp://gcc.gnu.org/pub/gcc/infrastructure/ for any special versions
459 _________________________________________________________________
461 Why can't I build a shared library?
463 When building a shared library you may get an error message from the
464 linker like `assert pure-text failed:' or `DP relative code in file'.
466 This kind of error occurs when you've failed to provide proper flags
467 to gcc when linking the shared library.
469 You can get this error even if all the .o files for the shared library
470 were compiled with the proper PIC option. When building a shared
471 library, gcc will compile additional code to be included in the
472 library. That additional code must also be compiled with the proper
475 Adding the proper PIC option (-fpic or -fPIC) to the link line which
476 creates the shared library will fix this problem on targets that
477 support PIC in this manner. For example:
478 gcc -c -fPIC myfile.c
479 gcc -shared -o libmyfile.so -fPIC myfile.o
480 _________________________________________________________________
482 When building C++, the linker says my constructors, destructors or virtual
483 tables are undefined, but I defined them
485 The ISO C++ Standard specifies that all virtual methods of a class
486 that are not pure-virtual must be defined, but does not require any
487 diagnostic for violations of this rule [class.virtual]/8. Based on
488 this assumption, GCC will only emit the implicitly defined
489 constructors, the assignment operator, the destructor and the virtual
490 table of a class in the translation unit that defines its first such
493 Therefore, if you fail to define this particular method, the linker
494 may complain about the lack of definitions for apparently unrelated
495 symbols. Unfortunately, in order to improve this error message, it
496 might be necessary to change the linker, and this can't always be
499 The solution is to ensure that all virtual methods that are not pure
500 are defined. Note that a destructor must be defined even if it is
501 declared pure-virtual [class.dtor]/7.
502 _________________________________________________________________
504 Will GCC someday include an incremental linker?
506 Incremental linking is part of the linker, not the compiler. As such,
507 GCC doesn't have anything to do with incremental linking. Depending on
508 what platform you use, it may be possible to tell GCC to use the
509 platform's native linker (e.g., Solaris' ild(1)).
513 1. http://gcc.gnu.org/faq.html
515 3. http://www.comeaucomputing.com/csc/faq.html
516 4. http://www.fortran.com/fortran/info.html
517 5. http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html
518 6. http://gcc.gnu.org/java/faq.html
519 7. http://gcc.gnu.org/faq.html#general
520 8. http://gcc.gnu.org/faq.html#open-development
521 9. http://gcc.gnu.org/faq.html#support
522 10. http://gcc.gnu.org/faq.html#platforms
523 11. http://gcc.gnu.org/faq.html#installation
524 12. http://gcc.gnu.org/faq.html#multiple
525 13. http://gcc.gnu.org/faq.html#rpath
526 14. http://gcc.gnu.org/faq.html#rpath
527 15. http://gcc.gnu.org/faq.html#gas
528 16. http://gcc.gnu.org/faq.html#environ
529 17. http://gcc.gnu.org/faq.html#optimizing
530 18. http://gcc.gnu.org/faq.html#iconv
531 19. http://gcc.gnu.org/faq.html#testsuite
532 20. http://gcc.gnu.org/faq.html#testoptions
533 21. http://gcc.gnu.org/faq.html#multipletests
534 22. http://gcc.gnu.org/faq.html#misc
535 23. http://gcc.gnu.org/faq.html#friend
536 24. http://gcc.gnu.org/faq.html#dso
537 25. http://gcc.gnu.org/faq.html#generated_files
538 26. http://gcc.gnu.org/faq.html#picflag-needed
539 27. http://gcc.gnu.org/faq.html#vtables
540 28. http://gcc.gnu.org/faq.html#incremental
541 29. http://gcc.gnu.org/faq.html#cathedral-vs-bazaar
542 30. http://gcc.gnu.org/bugs.html
543 31. http://gcc.gnu.org/install/specific.html
544 32. http://gcc.gnu.org/buildstat.html
545 33. http://gcc.gnu.org/faq.html#gas
546 34. http://gcc.gnu.org/install/specific.html
547 35. http://www.codesourcery.com/cxx-abi/
548 36. ftp://ftp.gnu.org/gnu/
549 37. ftp://gcc.gnu.org/pub/gcc/infrastructure/