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