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