GCC Frequently Asked QuestionsThe latest version of this document is always available at[1]http://gcc.gnu.org/faq.html.This FAQ tries to answer specific questions concerning GCC. Forgeneral information regarding C, C++, resp. Fortran please check the[2]comp.lang.c FAQ, [3]comp.std.c++ FAQ, and the [4]FortranInformation page.Other GCC-related FAQs: [5]libstdc++-v3, and [6]GCJ._________________________________________________________________Questions1. [7]General information1. [8]What is an open development model?2. [9]How do I get a bug fixed or a feature added?3. [10]Does GCC work on my platform?2. [11]Installation1. [12]How to install multiple versions of GCC2. [13]Dynamic linker is unable to find GCC libraries3. [14]libstdc++/libio tests fail badly with --enable-shared4. [15]GCC can not find GNU as/GNU ld5. [16]cpp: Usage:... Error6. [17]Optimizing the compiler itself7. [18]Why does libiconv get linked into jc1 on Solaris?3. [19]Testsuite problems1. [20]How do I pass flags like -fnew-abi to the testsuite?2. [21]How can I run the test suite with multiple options?4. [22]Miscellaneous1. [23]Friend Templates2. [24]dynamic_cast, throw, typeid don't work with sharedlibraries3. [25]Why do I need autoconf, bison, xgettext, automake, etc?4. [26]Why can't I build a shared library?5. [27]When building C++, the linker says my constructors,destructors or virtual tables are undefined, but I definedthem6. [28]Will GCC someday include an incremental linker?_________________________________________________________________General informationWhat is an open development model?We are using a bazaar style [29][1] approach to GCC development: wemake snapshots publicly available to anyone who wants to try them; wewelcome anyone to join the development mailing list. All of thediscussions on the development mailing list are available via the web.We're going to be making releases with a much higher frequency thanthey have been made in the past.In addition to weekly snapshots of the GCC development sources, wehave the sources readable from an SVN server by anyone. Furthermore weare using SVN to allow maintainers write access to the sources.There have been many potential GCC developers who were not able toparticipate in GCC development in the past. We want these people tohelp in any way they can; we ultimately want GCC to be the bestcompiler in the world.A compiler is a complicated piece of software, there will still bestrong central maintainers who will reject patches, who will demanddocumentation of implementations, and who will keep the level ofquality as high as it is today. Code that could use wider testing maybe integrated--code that is simply ill-conceived won't be.GCC is not the first piece of software to use this open developmentprocess; FreeBSD, the Emacs lisp repository, and the Linux kernel area few examples of the bazaar style of development.With GCC, we are adding new features and optimizations at a rate thathas not been done since the creation of gcc2; these additionsinevitably have a temporarily destabilizing effect. With the help ofdevelopers working together with this bazaar style development, theresulting stability and quality levels will be better than we've hadbefore.[1] We've been discussing different development models a lot overthe past few months. The paper which started all of this introducedtwo terms: A cathedral development model versus a bazaardevelopment model. The paper is written by Eric S. Raymond, it iscalled ``The Cathedral and the Bazaar''. The paper is a usefulstarting point for discussions._________________________________________________________________How do I get a bug fixed or a feature added?There are lots of ways to get something fixed. The list below may beincomplete, but it covers many of the common cases. These are listedroughly in order of decreasing difficulty for the average GCC user,meaning someone who is not skilled in the internals of GCC, and wheredifficulty is measured in terms of the time required to fix the bug.No alternative is better than any other; each has its benefits anddisadvantages.* Fix it yourself. This alternative will probably bring results, ifyou work hard enough, but will probably take a lot of time, and,depending on the quality of your work and the perceived benefitsof your changes, your code may or may not ever make it into anofficial release of GCC.* [30]Report the problem to the GCC bug tracking system and hopethat someone will be kind enough to fix it for you. While this iscertainly possible, and often happens, there is no guarantee thatit will. You should not expect the same response from this methodthat you would see from a commercial support organization sincethe people who read GCC bug reports, if they choose to help you,will be volunteering their time.* Hire someone to fix it for you. There are various companies andindividuals providing support for GCC. This alternative costsmoney, but is relatively likely to get results._________________________________________________________________Does GCC work on my platform?The host/target specific installation notes for GCC includeinformation about known problems with installing or using GCC onparticular platforms. These are included in the sources for a releasein INSTALL/specific.html, and the [31]latest version is alwaysavailable at the GCC web site. Reports of [32]successful builds forseveral versions of GCC are also available at the web site._________________________________________________________________InstallationHow to install multiple versions of GCCIt may be desirable to install multiple versions of the compiler onthe same system. This can be done by using different prefix paths atconfigure time and a few symlinks.Basically, configure the two compilers with different --prefixoptions, then build and install each compiler. Assume you want "gcc"to be the latest compiler and available in /usr/local/bin; also assumethat you want "gcc2" to be the older gcc2 compiler and also availablein /usr/local/bin.The easiest way to do this is to configure the new GCC with--prefix=/usr/local/gcc and the older gcc2 with--prefix=/usr/local/gcc2. Build and install both compilers. Then makea symlink from /usr/local/bin/gcc to /usr/local/gcc/bin/gcc and from/usr/local/bin/gcc2 to /usr/local/gcc2/bin/gcc. Create similar linksfor the "g++", "c++" and "g77" compiler drivers.An alternative to using symlinks is to configure with a--program-transform-name option. This option specifies a sed commandto process installed program names with. Using it you can, forinstance, have all the new GCC programs installed as "new-gcc" and thelike. You will still have to specify different --prefix options fornew GCC and old GCC, because it is only the executable program namesthat are transformed. The difference is that you (as administrator) donot have to set up symlinks, but must specify additional directoriesin your (as a user) PATH. A complication with --program-transform-nameis that the sed command invariably contains characters significant tothe shell, and these have to be escaped correctly, also it is notpossible to use "^" or "$" in the command. Here is the option toprefix "new-" to the new GCC installed programs:--program-transform-name='s,\\\\(.*\\\\),new-\\\\1,'With the above --prefix option, that will install the new GCC programsinto /usr/local/gcc/bin with names prefixed by "new-". You can use--program-transform-name if you have multiple versions of GCC, andwish to be sure about which version you are invoking.If you use --prefix, GCC may have difficulty locating a GNU assembleror linker on your system, [33]GCC can not find GNU as/GNU ld explainshow to deal with this.Another option that may be easier is to use the --program-prefix= or--program-suffix= options to configure. So if you're installing GCC2.95.2 and don't want to disturb the current version of GCC in/usr/local/bin/, you could doconfigure --program-suffix=-2.95.2 <other configure options>This should result in GCC being installed as /usr/local/bin/gcc-2.95.2instead of /usr/local/bin/gcc._________________________________________________________________Dynamic linker is unable to find GCC librariesThis problem manifests itself by programs not finding shared librariesthey depend on when the programs are started. Note this problem oftenmanifests itself with failures in the libio/libstdc++ tests afterconfiguring with --enable-shared and building GCC.GCC does not specify a runpath so that the dynamic linker can finddynamic libraries at runtime.The short explanation is that if you always pass a -R option to thelinker, then your programs become dependent on directories which maybe NFS mounted, and programs may hang unnecessarily when an NFS servergoes down.The problem is not programs that do require the directories; thoseprograms are going to hang no matter what you do. The problem isprograms that do not require the directories.SunOS effectively always passed a -R option for every -L option; thiswas a bad idea, and so it was removed for Solaris. We should notrecreate it.However, if you feel you really need such an option to be passedautomatically to the linker, you may add it to the GCC specs file.This file can be found in the same directory that contains cc1 (rungcc -print-prog-name=cc1 to find it). You may add linker flags such as-R or -rpath, depending on platform and linker, to the *link or *libspecs.Another alternative is to install a wrapper script around gcc, g++ orld that adds the appropriate directory to the environment variableLD_RUN_PATH or equivalent (again, it's platform-dependent).Yet another option, that works on a few platforms, is to hard-code thefull pathname of the library into its soname. This can only beaccomplished by modifying the appropriate .ml file withinlibstdc++/config (and also libg++/config, if you are building libg++),so that $(libdir)/ appears just before the library name in -soname or-h options._________________________________________________________________GCC can not find GNU as/GNU ldGCC searches the PATH for an assembler and a loader, but it only doesso after searching a directory list hard-coded in the GCC executables.Since, on most platforms, the hard-coded list includes directories inwhich the system assembler and loader can be found, you may have totake one of the following actions to arrange that GCC uses the GNUversions of those programs.To ensure that GCC finds the GNU assembler (the GNU loader), which arerequired by [34]some configurations, you should configure these withthe same --prefix option as you used for GCC. Then build & install GNUas (GNU ld) and proceed with building GCC.Another alternative is to create links to GNU as and ld in any of thedirectories printed by the command `gcc -print-search-dirs | grep'^programs:''. The link to `ld' should be named `real-ld' if `ld'already exists. If such links do not exist while you're compiling GCC,you may have to create them in the build directories too, within thegcc directory and in all the gcc/stage* subdirectories.GCC 2.95 allows you to specify the full pathname of the assembler andthe linker to use. The configure flags are `--with-as=/path/to/as' and`--with-ld=/path/to/ld'. GCC will try to use these pathnames beforelooking for `as' or `(real-)ld' in the standard search dirs. If, atconfigure-time, the specified programs are found to be GNU utilities,`--with-gnu-as' and `--with-gnu-ld' need not be used; these flags willbe auto-detected. One drawback of this option is that it won't allowyou to override the search path for assembler and linker withcommand-line options -B/path/ if the specified filenames exist._________________________________________________________________cpp: Usage:... ErrorIf you get an error like this when building GCC (particularly whenbuilding __mulsi3), then you likely have a problem with yourenvironment variables.cpp: Usage: /usr/lib/gcc-lib/i586-unknown-linux-gnulibc1/2.7.2.3/cpp[switches] input outputFirst look for an explicit '.' in either LIBRARY_PATH orGCC_EXEC_PREFIX from your environment. If you do not find an explicit'.', look for an empty pathname in those variables. Note that ':' ateither the start or end of these variables is an implicit '.' and willcause problems.Also note '::' in these paths will also cause similar problems._________________________________________________________________Optimizing the compiler itselfIf you want to test a particular optimization option, it's useful totry bootstrapping the compiler with that option turned on. Forexample, to test the -fssa option, you could bootstrap like this:make BOOT_CFLAGS="-O2 -fssa" bootstrap_________________________________________________________________Why does libiconv get linked into jc1 on Solaris?The Java front end requires iconv. If the compiler used to bootstrapGCC finds libiconv (because the GNU version of libiconv has beeninstalled in the same prefix as the bootstrap compiler), but the newlybuilt GCC does not find the library (because it will be installed witha different prefix), then a link-time error will occur when buildingjc1. This problem does not show up so often on platforms that havelibiconv in a default location (like /usr/lib) because then bothcompilers can find a library named libiconv, even though it is adifferent library.Using --disable-nls at configure-time does not prevent this problembecause jc1 uses iconv even in that case. Solutions includetemporarily removing the GNU libiconv, copying it to a defaultlocation such as /usr/lib/, and using --enable-languages atconfigure-time to disable Java._________________________________________________________________Testsuite problemsHow do I pass flags like -fnew-abi to the testsuite?If you invoke runtest directly, you can use the --tool_opts option,e.g:runtest --tool_opts "-fnew-abi -fno-honor-std" <other options>Or, if you use make check you can use the make variable RUNTESTFLAGS,e.g:make RUNTESTFLAGS="--tool_opts '-fnew-abi -fno-honor-std'" check-g++_________________________________________________________________How can I run the test suite with multiple options?If you invoke runtest directly, you can use the --target_board option,e.g:runtest --target_board "unix{-fPIC,-fpic,}" <other options>Or, if you use make check you can use the make variable RUNTESTFLAGS,e.g:make RUNTESTFLAGS="--target_board 'unix{-fPIC,-fpic,}'" check-gccEither of these examples will run the tests three times. Once with-fPIC, once with -fpic, and once with no additional flags.This technique is particularly useful on multilibbed targets._________________________________________________________________MiscellaneousFriend TemplatesIn order to make a specialization of a template function a friend of a(possibly template) class, you must explicitly state that the friendfunction is a template, by appending angle brackets to its name, andthis template function must have been declared already. Here's anexample:template <typename T> class foo {friend void bar(foo<T>);}The above declaration declares a non-template function named bar, soit must be explicitly defined for each specialization of foo. Atemplate definition of bar won't do, because it is unrelated with thenon-template declaration above. So you'd have to end up writing:void bar(foo<int>) { /* ... */ }void bar(foo<void>) { /* ... */ }If you meant bar to be a template function, you should haveforward-declared it as follows. Note that, since the template functiondeclaration refers to the template class, the template class must beforward-declared too:template <typename T>class foo;template <typename T>void bar(foo<T>);template <typename T>class foo {friend void bar<>(foo<T>);};template <typename T>void bar(foo<T>) { /* ... */ }In this case, the template argument list could be left empty, becauseit can be implicitly deduced from the function arguments, but theangle brackets must be present, otherwise the declaration will betaken as a non-template function. Furthermore, in some cases, you mayhave to explicitly specify the template arguments, to removeambiguity.An error in the last public comment draft of the ANSI/ISO C++ Standardand the fact that previous releases of GCC would accept such frienddeclarations as template declarations has led people to believe thatthe forward declaration was not necessary, but, according to the finalversion of the Standard, it is._________________________________________________________________dynamic_cast, throw, typeid don't work with shared librariesThe new C++ ABI in the GCC 3.0 series uses address comparisons, ratherthan string compares, to determine type equality. This leads to betterperformance. Like other objects that have to be present in the finalexecutable, these std::type_info objects have what is called vaguelinkage because they are not tightly bound to any one particulartranslation unit (object file). The compiler has to emit them in anytranslation unit that requires their presence, and then rely on thelinking and loading process to make sure that only one of them isactive in the final executable. With static linking all of thesesymbols are resolved at link time, but with dynamic linking, furtherresolution occurs at load time. You have to ensure that objects withina shared library are resolved against objects in the executable andother shared libraries.* For a program which is linked against a shared library, noadditional precautions are needed.* You cannot create a shared library with the "-Bsymbolic" option,as that prevents the resolution described above.* If you use dlopen to explicitly load code from a shared library,you must do several things. First, export global symbols from theexecutable by linking it with the "-E" flag (you will have tospecify this as "-Wl,-E" if you are invoking the linker in theusual manner from the compiler driver, g++). You must also makethe external symbols in the loaded library available forsubsequent libraries by providing the RTLD_GLOBAL flag to dlopen.The symbol resolution can be immediate or lazy.Template instantiations are another, user visible, case of objectswith vague linkage, which needs similar resolution. If you do not takethe above precautions, you may discover that a template instantiationwith the same argument list, but instantiated in multiple translationunits, has several addresses, depending in which translation unit theaddress is taken. (This is not an exhaustive list of the kind ofobjects which have vague linkage and are expected to be resolvedduring linking & loading.)If you are worried about different objects with the same namecolliding during the linking or loading process, then you should usenamespaces to disambiguate them. Giving distinct objects with globallinkage the same name is a violation of the One Definition Rule (ODR)[basic.def.odr].For more details about the way that GCC implements these and other C++features, please read the [35]ABI specification. Note thestd::type_info objects which must be resolved all begin with "_ZTS".Refer to ld's documentation for a description of the "-E" &"-Bsymbolic" flags._________________________________________________________________Why do I need autoconf, bison, xgettext, automake, etc?If you're using diffs up dated from one snapshot to the next, or ifyou're using the SVN repository, you may need several additionalprograms to build GCC.These include, but are not necessarily limited to autoconf, automake,bison, and xgettext.This is necessary because neither diff nor cvs keep timestampscorrect. This causes problems for generated files as "make" may thinkthose generated files are out of date and try to regenerate them.An easy way to work around this problem is to use the gcc_updatescript in the contrib subdirectory of GCC, which handles thistransparently without requiring installation of any additional tools.When building from diffs or SVN or if you modified some sources, youmay also need to obtain development versions of some GNU tools, as theproduction versions do not necessarily handle all features needed torebuild GCC.In general, the current versions of these tools from[36]ftp://ftp.gnu.org/gnu/ will work. At present, Autoconf 2.50 is notsupported, and you will need to use Autoconf 2.13; work is in progressto fix this problem. Also look at[37]ftp://gcc.gnu.org/pub/gcc/infrastructure/ for any special versionsof packages._________________________________________________________________Why can't I build a shared library?When building a shared library you may get an error message from thelinker like `assert pure-text failed:' or `DP relative code in file'.This kind of error occurs when you've failed to provide proper flagsto gcc when linking the shared library.You can get this error even if all the .o files for the shared librarywere compiled with the proper PIC option. When building a sharedlibrary, gcc will compile additional code to be included in thelibrary. That additional code must also be compiled with the properPIC option.Adding the proper PIC option (-fpic or -fPIC) to the link line whichcreates the shared library will fix this problem on targets thatsupport PIC in this manner. For example:gcc -c -fPIC myfile.cgcc -shared -o libmyfile.so -fPIC myfile.o_________________________________________________________________When building C++, the linker says my constructors, destructors or virtualtables are undefined, but I defined themThe ISO C++ Standard specifies that all virtual methods of a classthat are not pure-virtual must be defined, but does not require anydiagnostic for violations of this rule [class.virtual]/8. Based onthis assumption, GCC will only emit the implicitly definedconstructors, the assignment operator, the destructor and the virtualtable of a class in the translation unit that defines its first suchnon-inline method.Therefore, if you fail to define this particular method, the linkermay complain about the lack of definitions for apparently unrelatedsymbols. Unfortunately, in order to improve this error message, itmight be necessary to change the linker, and this can't always bedone.The solution is to ensure that all virtual methods that are not pureare defined. Note that a destructor must be defined even if it isdeclared pure-virtual [class.dtor]/7._________________________________________________________________Will GCC someday include an incremental linker?Incremental linking is part of the linker, not the compiler. As such,GCC doesn't have anything to do with incremental linking. Depending onwhat platform you use, it may be possible to tell GCC to use theplatform's native linker (e.g., Solaris' ild(1)).References1. http://gcc.gnu.org/faq.html2. http://c-faq.com/3. http://www.comeaucomputing.com/csc/faq.html4. http://www.fortran.com/fortran/info.html5. http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html6. http://gcc.gnu.org/java/faq.html7. http://gcc.gnu.org/faq.html#general8. http://gcc.gnu.org/faq.html#open-development9. http://gcc.gnu.org/faq.html#support10. http://gcc.gnu.org/faq.html#platforms11. http://gcc.gnu.org/faq.html#installation12. http://gcc.gnu.org/faq.html#multiple13. http://gcc.gnu.org/faq.html#rpath14. http://gcc.gnu.org/faq.html#rpath15. http://gcc.gnu.org/faq.html#gas16. http://gcc.gnu.org/faq.html#environ17. http://gcc.gnu.org/faq.html#optimizing18. http://gcc.gnu.org/faq.html#iconv19. http://gcc.gnu.org/faq.html#testsuite20. http://gcc.gnu.org/faq.html#testoptions21. http://gcc.gnu.org/faq.html#multipletests22. http://gcc.gnu.org/faq.html#misc23. http://gcc.gnu.org/faq.html#friend24. http://gcc.gnu.org/faq.html#dso25. http://gcc.gnu.org/faq.html#generated_files26. http://gcc.gnu.org/faq.html#picflag-needed27. http://gcc.gnu.org/faq.html#vtables28. http://gcc.gnu.org/faq.html#incremental29. http://gcc.gnu.org/faq.html#cathedral-vs-bazaar30. http://gcc.gnu.org/bugs.html31. http://gcc.gnu.org/install/specific.html32. http://gcc.gnu.org/buildstat.html33. http://gcc.gnu.org/faq.html#gas34. http://gcc.gnu.org/install/specific.html35. http://www.codesourcery.com/cxx-abi/36. ftp://ftp.gnu.org/gnu/37. ftp://gcc.gnu.org/pub/gcc/infrastructure/