faq.html 28 KB

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