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