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