*: Regenerate.
[gcc.git] / libstdc++-v3 / doc / html / manual / using_dynamic_or_shared.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Linking</title><meta name="generator" content="DocBook XSL-NS Stylesheets V1.76.1"><meta name="keywords" content="
2 ISO C++
3 ,
4 library
5 "><meta name="keywords" content="
6 ISO C++
7 ,
8 runtime
9 ,
10 library
11 "><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 bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><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" title="Linking"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="manual.intro.using.linkage"></a>Linking</h2></div></div></div><div class="section" title="Almost Nothing"><div class="titlepage"><div><div><h3 class="title"><a name="manual.intro.using.linkage.freestanding"></a>Almost Nothing</h3></div></div></div><p>
12 Or as close as it gets: freestanding. This is a minimal
13 configuration, with only partial support for the standard
14 library. Assume only the following header files can be used:
15 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
16 <code class="filename">cstdarg</code>
17 </p></li><li class="listitem"><p>
18 <code class="filename">cstddef</code>
19 </p></li><li class="listitem"><p>
20 <code class="filename">cstdlib</code>
21 </p></li><li class="listitem"><p>
22 <code class="filename">exception</code>
23 </p></li><li class="listitem"><p>
24 <code class="filename">limits</code>
25 </p></li><li class="listitem"><p>
26 <code class="filename">new</code>
27 </p></li><li class="listitem"><p>
28 <code class="filename">exception</code>
29 </p></li><li class="listitem"><p>
30 <code class="filename">typeinfo</code>
31 </p></li></ul></div><p>
32 In addition, throw in
33 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
34 <code class="filename">cxxabi.h</code>.
35 </p></li></ul></div><p>
36 In the
37 C++11 <a class="link" href="using.html#manual.intro.using.flags" title="Command Options">dialect</a> add
38 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
39 <code class="filename">initializer_list</code>
40 </p></li><li class="listitem"><p>
41 <code class="filename">type_traits</code>
42 </p></li></ul></div><p> There exists a library that offers runtime support for
43 just these headers, and it is called
44 <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:
45 </p><p>
46 <span class="command"><strong>gcc foo.cc -lsupc++</strong></span>
47 </p><p>
48 No attempt is made to verify that only the minimal subset
49 identified above is actually used at compile time. Violations
50 are diagnosed as undefined symbols at link time.
51 </p></div><div class="section" title="Finding Dynamic or Shared Libraries"><div class="titlepage"><div><div><h3 class="title"><a name="manual.intro.using.linkage.dynamic"></a>Finding Dynamic or Shared Libraries</h3></div></div></div><p>
52 If the only library built is the static library
53 (<code class="filename">libstdc++.a</code>), or if
54 specifying static linking, this section is can be skipped. But
55 if building or using a shared library
56 (<code class="filename">libstdc++.so</code>), then
57 additional location information will need to be provided.
58 </p><p>
59 But how?
60 </p><p>
61 A quick read of the relevant part of the GCC
62 manual, <a class="link" href="http://gcc.gnu.org/onlinedocs/gcc/Invoking-G_002b_002b.html#Invoking-G_002b_002b" target="_top">Compiling
63 C++ Programs</a>, specifies linking against a C++
64 library. More details from the
65 GCC <a class="link" href="http://gcc.gnu.org/faq.html#rpath" target="_top">FAQ</a>,
66 which states <span class="emphasis"><em>GCC does not, by default, specify a
67 location so that the dynamic linker can find dynamic libraries at
68 runtime.</em></span>
69 </p><p>
70 Users will have to provide this information.
71 </p><p>
72 Methods vary for different platforms and different styles, and
73 are printed to the screen during installation. To summarize:
74 </p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
75 At runtime set <code class="literal">LD_LIBRARY_PATH</code> in your
76 environment correctly, so that the shared library for
77 libstdc++ can be found and loaded. Be certain that you
78 understand all of the other implications and behavior
79 of <code class="literal">LD_LIBRARY_PATH</code> first.
80 </p></li><li class="listitem"><p>
81 Compile the path to find the library at runtime into the
82 program. This can be done by passing certain options to
83 <span class="command"><strong>g++</strong></span>, which will in turn pass them on to
84 the linker. The exact format of the options is dependent on
85 which linker you use:
86 </p><div class="itemizedlist"><ul class="itemizedlist" type="circle"><li class="listitem"><p>
87 GNU ld (default on GNU/Linux):
88 <code class="literal">-Wl,-rpath,</code><code class="filename">destdir/lib</code>
89 </p></li><li class="listitem"><p>
90 Solaris ld:
91 <code class="literal">-Wl,-R</code><code class="filename">destdir/lib</code>
92 </p></li></ul></div></li><li class="listitem"><p>
93 Some linkers allow you to specify the path to the library by
94 setting <code class="literal">LD_RUN_PATH</code> in your environment
95 when linking.
96 </p></li><li class="listitem"><p>
97 On some platforms the system administrator can configure the
98 dynamic linker to always look for libraries in
99 <code class="filename">destdir/lib</code>, for example
100 by using the <span class="command"><strong>ldconfig</strong></span> utility on GNU/Linux
101 or the <span class="command"><strong>crle</strong></span> utility on Solaris. This is a
102 system-wide change which can make the system unusable so if you
103 are unsure then use one of the other methods described above.
104 </p></li></ul></div><p>
105 Use the <span class="command"><strong>ldd</strong></span> utility on the linked executable
106 to show
107 which <code class="filename">libstdc++.so</code>
108 library the system will get at runtime.
109 </p><p>
110 A <code class="filename">libstdc++.la</code> file is
111 also installed, for use with Libtool. If you use Libtool to
112 create your executables, these details are taken care of for
113 you.
114 </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>