1 <?xml version=
"1.0" encoding=
"UTF-8" standalone=
"no"?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns=
"http://www.w3.org/1999/xhtml"><head><meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8" /><title>Linking
</title><meta name=
"generator" content=
"DocBook XSL-NS Stylesheets V1.78.1" /><meta name=
"keywords" content=
"ISO C++, library" /><meta name=
"keywords" content=
"ISO C++, runtime, library" /><link rel=
"home" href=
"../index.html" title=
"The GNU C++ Library" /><link rel=
"up" href=
"using.html" title=
"Chapter 3. Using" /><link rel=
"prev" href=
"using_namespaces.html" title=
"Namespaces" /><link rel=
"next" href=
"using_concurrency.html" title=
"Concurrency" /></head><body><div class=
"navheader"><table width=
"100%" summary=
"Navigation header"><tr><th colspan=
"3" align=
"center">Linking
</th></tr><tr><td width=
"20%" align=
"left"><a accesskey=
"p" href=
"using_namespaces.html">Prev
</a> </td><th width=
"60%" align=
"center">Chapter
3. Using
</th><td width=
"20%" align=
"right"> <a accesskey=
"n" href=
"using_concurrency.html">Next
</a></td></tr></table><hr /></div><div class=
"section"><div class=
"titlepage"><div><div><h2 class=
"title" style=
"clear: both"><a id=
"manual.intro.using.linkage"></a>Linking
</h2></div></div></div><div class=
"section"><div class=
"titlepage"><div><div><h3 class=
"title"><a id=
"manual.intro.using.linkage.freestanding"></a>Almost Nothing
</h3></div></div></div><p>
3 Or as close as it gets: freestanding. This is a minimal
4 configuration, with only partial support for the standard
5 library. Assume only the following header files can be used:
6 </p><div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: disc; "><li class=
"listitem"><p>
7 <code class=
"filename">cstdarg
</code>
8 </p></li><li class=
"listitem"><p>
9 <code class=
"filename">cstddef
</code>
10 </p></li><li class=
"listitem"><p>
11 <code class=
"filename">cstdlib
</code>
12 </p></li><li class=
"listitem"><p>
13 <code class=
"filename">exception
</code>
14 </p></li><li class=
"listitem"><p>
15 <code class=
"filename">limits
</code>
16 </p></li><li class=
"listitem"><p>
17 <code class=
"filename">new
</code>
18 </p></li><li class=
"listitem"><p>
19 <code class=
"filename">exception
</code>
20 </p></li><li class=
"listitem"><p>
21 <code class=
"filename">typeinfo
</code>
22 </p></li></ul></div><p>
24 </p><div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: disc; "><li class=
"listitem"><p>
25 <code class=
"filename">cxxabi.h
</code>.
26 </p></li></ul></div><p>
28 C++
11 <a class=
"link" href=
"using.html#manual.intro.using.flags" title=
"Command Options">dialect
</a> add
29 </p><div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: disc; "><li class=
"listitem"><p>
30 <code class=
"filename">initializer_list
</code>
31 </p></li><li class=
"listitem"><p>
32 <code class=
"filename">type_traits
</code>
33 </p></li></ul></div><p> There exists a library that offers runtime support for
34 just these headers, and it is called
35 <code class=
"filename">libsupc++.a
</code>. To use it, compile with
<span class=
"command"><strong>gcc
</strong></span> instead of
<span class=
"command"><strong>g++
</strong></span>, like so:
37 <span class=
"command"><strong>gcc foo.cc -lsupc++
</strong></span>
39 No attempt is made to verify that only the minimal subset
40 identified above is actually used at compile time. Violations
41 are diagnosed as undefined symbols at link time.
42 </p></div><div class=
"section"><div class=
"titlepage"><div><div><h3 class=
"title"><a id=
"manual.intro.using.linkage.dynamic"></a>Finding Dynamic or Shared Libraries
</h3></div></div></div><p>
43 If the only library built is the static library
44 (
<code class=
"filename">libstdc++.a
</code>), or if
45 specifying static linking, this section is can be skipped. But
46 if building or using a shared library
47 (
<code class=
"filename">libstdc++.so
</code>), then
48 additional location information will need to be provided.
52 A quick read of the relevant part of the GCC
53 manual,
<a class=
"link" href=
"http://gcc.gnu.org/onlinedocs/gcc/Invoking-G_002b_002b.html#Invoking-G_002b_002b" target=
"_top">Compiling
54 C++ Programs
</a>, specifies linking against a C++
55 library. More details from the
56 GCC
<a class=
"link" href=
"http://gcc.gnu.org/faq.html#rpath" target=
"_top">FAQ
</a>,
57 which states
<span class=
"emphasis"><em>GCC does not, by default, specify a
58 location so that the dynamic linker can find dynamic libraries at
61 Users will have to provide this information.
63 Methods vary for different platforms and different styles, and
64 are printed to the screen during installation. To summarize:
65 </p><div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: disc; "><li class=
"listitem"><p>
66 At runtime set
<code class=
"literal">LD_LIBRARY_PATH
</code> in your
67 environment correctly, so that the shared library for
68 libstdc++ can be found and loaded. Be certain that you
69 understand all of the other implications and behavior
70 of
<code class=
"literal">LD_LIBRARY_PATH
</code> first.
71 </p></li><li class=
"listitem"><p>
72 Compile the path to find the library at runtime into the
73 program. This can be done by passing certain options to
74 <span class=
"command"><strong>g++
</strong></span>, which will in turn pass them on to
75 the linker. The exact format of the options is dependent on
77 </p><div class=
"itemizedlist"><ul class=
"itemizedlist" style=
"list-style-type: circle; "><li class=
"listitem"><p>
78 GNU ld (default on GNU/Linux):
79 <code class=
"literal">-Wl,-rpath,
</code><code class=
"filename">destdir/lib
</code>
80 </p></li><li class=
"listitem"><p>
82 <code class=
"literal">-Wl,-R
</code><code class=
"filename">destdir/lib
</code>
83 </p></li></ul></div></li><li class=
"listitem"><p>
84 Some linkers allow you to specify the path to the library by
85 setting
<code class=
"literal">LD_RUN_PATH
</code> in your environment
87 </p></li><li class=
"listitem"><p>
88 On some platforms the system administrator can configure the
89 dynamic linker to always look for libraries in
90 <code class=
"filename">destdir/lib
</code>, for example
91 by using the
<span class=
"command"><strong>ldconfig
</strong></span> utility on GNU/Linux
92 or the
<span class=
"command"><strong>crle
</strong></span> utility on Solaris. This is a
93 system-wide change which can make the system unusable so if you
94 are unsure then use one of the other methods described above.
95 </p></li></ul></div><p>
96 Use the
<span class=
"command"><strong>ldd
</strong></span> utility on the linked executable
98 which
<code class=
"filename">libstdc++.so
</code>
99 library the system will get at runtime.
101 A
<code class=
"filename">libstdc++.la
</code> file is
102 also installed, for use with Libtool. If you use Libtool to
103 create your executables, these details are taken care of for
105 </p></div></div><div class=
"navfooter"><hr /><table width=
"100%" summary=
"Navigation footer"><tr><td width=
"40%" align=
"left"><a accesskey=
"p" href=
"using_namespaces.html">Prev
</a> </td><td width=
"20%" align=
"center"><a accesskey=
"u" href=
"using.html">Up
</a></td><td width=
"40%" align=
"right"> <a accesskey=
"n" href=
"using_concurrency.html">Next
</a></td></tr><tr><td width=
"40%" align=
"left" valign=
"top">Namespaces
</td><td width=
"20%" align=
"center"><a accesskey=
"h" href=
"../index.html">Home
</a></td><td width=
"40%" align=
"right" valign=
"top"> Concurrency
</td></tr></table></div></body></html>