URL
https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk
Subversion Repositories openrisc_me
[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [FAQ] - Rev 321
Go to most recent revision | Compare with Previous | Blame | View Log
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. For generalinformation regarding C, C++, resp. Fortran please check the [2]comp.lang.cFAQ, [3]comp.std.c++ FAQ, and the [4]Fortran Information page.Other GCC-related FAQs: [5]libstdc++-v3, and [6]GCJ._________________________________________________________________Questions1. [7]General information1. [8]How do I get a bug fixed or a feature added?2. [9]Does GCC work on my platform?2. [10]Installation1. [11]How to install multiple versions of GCC2. [12]Dynamic linker is unable to find GCC libraries3. [13]libstdc++/libio tests fail badly with --enable-shared4. [14]GCC can not find GNU as/GNU ld5. [15]cpp: Usage:... Error6. [16]Optimizing the compiler itself7. [17]Why does libiconv get linked into jc1 on Solaris?3. [18]Testsuite problems1. [19]How do I pass flags like -fnew-abi to the testsuite?2. [20]How can I run the test suite with multiple options?4. [21]Miscellaneous1. [22]Friend Templates2. [23]dynamic_cast, throw, typeid don't work with shared libraries3. [24]Why do I need autoconf, bison, xgettext, automake, etc?4. [25]Why can't I build a shared library?5. [26]When building C++, the linker says my constructors, destructorsor virtual tables are undefined, but I defined them_________________________________________________________________General informationHow 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 listed roughlyin order of decreasing difficulty for the average GCC user, meaning someonewho is not skilled in the internals of GCC, and where difficulty is measuredin terms of the time required to fix the bug. No alternative is better thanany other; each has its benefits and disadvantages.* Fix it yourself. This alternative will probably bring results, if youwork hard enough, but will probably take a lot of time, and, dependingon the quality of your work and the perceived benefits of your changes,your code may or may not ever make it into an official release of GCC.* [27]Report the problem to the GCC bug tracking system and hope thatsomeone will be kind enough to fix it for you. While this is certainlypossible, and often happens, there is no guarantee that it will. Youshould not expect the same response from this method that you would seefrom a commercial support organization since the people who read GCC bugreports, 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 costs money, butis relatively likely to get results._________________________________________________________________Does GCC work on my platform?The host/target specific installation notes for GCC include informationabout known problems with installing or using GCC on particular platforms.These are included in the sources for a release in INSTALL/specific.html,and the [28]latest version is always available at the GCC web site. Reportsof [29]successful builds for several versions of GCC are also available atthe web site._________________________________________________________________InstallationHow to install multiple versions of GCCIt may be desirable to install multiple versions of the compiler on the samesystem. This can be done by using different prefix paths at configure timeand a few symlinks.Basically, configure the two compilers with different --prefix options, thenbuild and install each compiler. Assume you want "gcc" to be the latestcompiler and available in /usr/local/bin; also assume that you want "gcc2"to be the older gcc2 compiler and also available in /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 make a 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 links for 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 command toprocess installed program names with. Using it you can, for instance, haveall the new GCC programs installed as "new-gcc" and the like. You will stillhave to specify different --prefix options for new GCC and old GCC, becauseit is only the executable program names that are transformed. The differenceis that you (as administrator) do not have to set up symlinks, but mustspecify additional directories in your (as a user) PATH. A complication with--program-transform-name is that the sed command invariably containscharacters significant to the shell, and these have to be escaped correctly,also it is not possible to use "^" or "$" in the command. Here is the optionto prefix "new-" to the new GCC installed programs:--program-transform-name='s,\\\\(.*\\\\),new-\\\\1,'With the above --prefix option, that will install the new GCC programs into/usr/local/gcc/bin with names prefixed by "new-". You can use--program-transform-name if you have multiple versions of GCC, and wish tobe sure about which version you are invoking.If you use --prefix, GCC may have difficulty locating a GNU assembler orlinker on your system, [30]GCC can not find GNU as/GNU ld explains how todeal 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 GCC 2.95.2and don't want to disturb the current version of GCC in /usr/local/bin/, youcould 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 libraries theydepend on when the programs are started. Note this problem often manifestsitself with failures in the libio/libstdc++ tests after configuring with--enable-shared and building GCC.GCC does not specify a runpath so that the dynamic linker can find dynamiclibraries at runtime.The short explanation is that if you always pass a -R option to the linker,then your programs become dependent on directories which may be NFS mounted,and programs may hang unnecessarily when an NFS server goes down.The problem is not programs that do require the directories; those programsare going to hang no matter what you do. The problem is programs that do notrequire the directories.SunOS effectively always passed a -R option for every -L option; this was abad idea, and so it was removed for Solaris. We should not recreate 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 filecan be found in the same directory that contains cc1 (run gcc-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 *lib specs.Another alternative is to install a wrapper script around gcc, g++ or ldthat adds the appropriate directory to the environment variable LD_RUN_PATHor equivalent (again, it's platform-dependent).Yet another option, that works on a few platforms, is to hard-code the fullpathname of the library into its soname. This can only be accomplished bymodifying the appropriate .ml file within libstdc++/config (and alsolibg++/config, if you are building libg++), so that $(libdir)/ appears justbefore 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 does soafter searching a directory list hard-coded in the GCC executables. Since,on most platforms, the hard-coded list includes directories in which thesystem assembler and loader can be found, you may have to take one of thefollowing actions to arrange that GCC uses the GNU versions of thoseprograms.To ensure that GCC finds the GNU assembler (the GNU loader), which arerequired by [31]some configurations, you should configure these with thesame --prefix option as you used for GCC. Then build & install GNU as (GNUld) 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' alreadyexists. If such links do not exist while you're compiling GCC, you may haveto create them in the build directories too, within the gcc directory and inall the gcc/stage* subdirectories.GCC 2.95 allows you to specify the full pathname of the assembler and thelinker to use. The configure flags are `--with-as=/path/to/as' and`--with-ld=/path/to/ld'. GCC will try to use these pathnames before lookingfor `as' or `(real-)ld' in the standard search dirs. If, at configure-time,the specified programs are found to be GNU utilities, `--with-gnu-as' and`--with-gnu-ld' need not be used; these flags will be auto-detected. Onedrawback of this option is that it won't allow you to override the searchpath for assembler and linker with command-line options -B/path/ if thespecified filenames exist._________________________________________________________________cpp: Usage:... ErrorIf you get an error like this when building GCC (particularly when building__mulsi3), then you likely have a problem with your environment 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 or GCC_EXEC_PREFIXfrom your environment. If you do not find an explicit '.', look for an emptypathname in those variables. Note that ':' at either the start or end ofthese variables is an implicit '.' and will cause 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 to trybootstrapping the compiler with that option turned on. For example, to testthe -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 bootstrap GCCfinds libiconv (because the GNU version of libiconv has been installed inthe same prefix as the bootstrap compiler), but the newly built GCC does notfind the library (because it will be installed with a different prefix),then a link-time error will occur when building jc1. This problem does notshow up so often on platforms that have libiconv in a default location (like/usr/lib) because then both compilers can find a library named libiconv,even though it is a different library.Using --disable-nls at configure-time does not prevent this problem becausejc1 uses iconv even in that case. Solutions include temporarily removing theGNU libiconv, copying it to a default location such as /usr/lib/, and using--enable-languages at configure-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, and thistemplate function must have been declared already. Here's an example:template <typename T> class foo {friend void bar(foo<T>);}The above declaration declares a non-template function named bar, so it mustbe explicitly defined for each specialization of foo. A template definitionof bar won't do, because it is unrelated with the non-template declarationabove. 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 have forward-declaredit as follows. Note that, since the template function declaration refers tothe template class, the template class must be forward-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, because it canbe implicitly deduced from the function arguments, but the angle bracketsmust be present, otherwise the declaration will be taken as a non-templatefunction. Furthermore, in some cases, you may have to explicitly specify thetemplate arguments, to remove ambiguity.An error in the last public comment draft of the ANSI/ISO C++ Standard andthe fact that previous releases of GCC would accept such friend declarationsas template declarations has led people to believe that the forwarddeclaration was not necessary, but, according to the final version of theStandard, it is._________________________________________________________________dynamic_cast, throw, typeid don't work with shared librariesThe new C++ ABI in the GCC 3.0 series uses address comparisons, rather thanstring 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 vague linkagebecause they are not tightly bound to any one particular translation unit(object file). The compiler has to emit them in any translation unit thatrequires their presence, and then rely on the linking and loading process tomake sure that only one of them is active in the final executable. Withstatic linking all of these symbols are resolved at link time, but withdynamic linking, further resolution occurs at load time. You have to ensurethat objects within a shared library are resolved against objects in theexecutable and other shared libraries.* For a program which is linked against a shared library, no additionalprecautions are needed.* You cannot create a shared library with the "-Bsymbolic" option, as thatprevents the resolution described above.* If you use dlopen to explicitly load code from a shared library, youmust do several things. First, export global symbols from the executableby linking it with the "-E" flag (you will have to specify this as"-Wl,-E" if you are invoking the linker in the usual manner from thecompiler driver, g++). You must also make the external symbols in theloaded library available for subsequent libraries by providing theRTLD_GLOBAL flag to dlopen. The symbol resolution can be immediate orlazy.Template instantiations are another, user visible, case of objects withvague linkage, which needs similar resolution. If you do not take the aboveprecautions, you may discover that a template instantiation with the sameargument list, but instantiated in multiple translation units, has severaladdresses, depending in which translation unit the address is taken. (Thisis not an exhaustive list of the kind of objects which have vague linkageand are expected to be resolved during linking & loading.)If you are worried about different objects with the same name collidingduring the linking or loading process, then you should use namespaces todisambiguate them. Giving distinct objects with global linkage the same nameis 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 [32]ABI specification. Note the std::type_infoobjects which must be resolved all begin with "_ZTS". Refer to ld'sdocumentation 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 if you'reusing the SVN repository, you may need several additional programs to buildGCC.These include, but are not necessarily limited to autoconf, automake, bison,and xgettext.This is necessary because neither diff nor cvs keep timestamps correct. Thiscauses problems for generated files as "make" may think those generatedfiles are out of date and try to regenerate them.An easy way to work around this problem is to use the gcc_update script inthe contrib subdirectory of GCC, which handles this transparently withoutrequiring installation of any additional tools.When building from diffs or SVN or if you modified some sources, you mayalso need to obtain development versions of some GNU tools, as theproduction versions do not necessarily handle all features needed to rebuildGCC.In general, the current versions of these tools from[33]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 progress tofix this problem. Also look at [34]ftp://gcc.gnu.org/pub/gcc/infrastructure/for any special versions of packages._________________________________________________________________Why can't I build a shared library?When building a shared library you may get an error message from the linkerlike `assert pure-text failed:' or `DP relative code in file'.This kind of error occurs when you've failed to provide proper flags to gccwhen linking the shared library.You can get this error even if all the .o files for the shared library werecompiled with the proper PIC option. When building a shared library, gccwill compile additional code to be included in the library. That additionalcode must also be compiled with the proper PIC option.Adding the proper PIC option (-fpic or -fPIC) to the link line which createsthe shared library will fix this problem on targets that support PIC in thismanner. 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 class that arenot pure-virtual must be defined, but does not require any diagnostic forviolations of this rule [class.virtual]/8. Based on this assumption, GCCwill only emit the implicitly defined constructors, the assignment operator,the destructor and the virtual table of a class in the translation unit thatdefines its first such non-inline method.Therefore, if you fail to define this particular method, the linker maycomplain about the lack of definitions for apparently unrelated symbols.Unfortunately, in order to improve this error message, it might be necessaryto change the linker, and this can't always be done.The solution is to ensure that all virtual methods that are not pure aredefined. Note that a destructor must be defined even if it is declaredpure-virtual [class.dtor]/7.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#support9. http://gcc.gnu.org/faq.html#platforms10. http://gcc.gnu.org/faq.html#installation11. http://gcc.gnu.org/faq.html#multiple12. http://gcc.gnu.org/faq.html#rpath13. http://gcc.gnu.org/faq.html#rpath14. http://gcc.gnu.org/faq.html#gas15. http://gcc.gnu.org/faq.html#environ16. http://gcc.gnu.org/faq.html#optimizing17. http://gcc.gnu.org/faq.html#iconv18. http://gcc.gnu.org/faq.html#testsuite19. http://gcc.gnu.org/faq.html#testoptions20. http://gcc.gnu.org/faq.html#multipletests21. http://gcc.gnu.org/faq.html#misc22. http://gcc.gnu.org/faq.html#friend23. http://gcc.gnu.org/faq.html#dso24. http://gcc.gnu.org/faq.html#generated_files25. http://gcc.gnu.org/faq.html#picflag-needed26. http://gcc.gnu.org/faq.html#vtables27. http://gcc.gnu.org/bugs.html28. http://gcc.gnu.org/install/specific.html29. http://gcc.gnu.org/buildstat.html30. http://gcc.gnu.org/faq.html#gas31. http://gcc.gnu.org/install/specific.html32. http://www.codesourcery.com/cxx-abi/33. ftp://ftp.gnu.org/gnu/34. ftp://gcc.gnu.org/pub/gcc/infrastructure/
Go to most recent revision | Compare with Previous | Blame | View Log
