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