1 |
424 |
jeremybenn |
<?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">
|
3 |
|
|
<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 Stylesheets V1.75.2" /><meta name="keywords" content=" ISO C++ , library " /><link rel="home" href="../spine.html" title="The GNU C++ Library Documentation" /><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="sect1" title="Linking"><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="sect2" title="Almost Nothing"><div class="titlepage"><div><div><h3 class="title"><a id="manual.intro.using.linkage.freestanding"></a>Almost Nothing</h3></div></div></div><p>
|
4 |
|
|
Or as close as it gets: freestanding. This is a minimal
|
5 |
|
|
configuration, with only partial support for the standard
|
6 |
|
|
library. Assume only the following header files can be used:
|
7 |
|
|
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
|
8 |
|
|
<code class="filename">cstdarg</code>
|
9 |
|
|
</p></li><li class="listitem"><p>
|
10 |
|
|
<code class="filename">cstddef</code>
|
11 |
|
|
</p></li><li class="listitem"><p>
|
12 |
|
|
<code class="filename">cstdlib</code>
|
13 |
|
|
</p></li><li class="listitem"><p>
|
14 |
|
|
<code class="filename">exception</code>
|
15 |
|
|
</p></li><li class="listitem"><p>
|
16 |
|
|
<code class="filename">limits</code>
|
17 |
|
|
</p></li><li class="listitem"><p>
|
18 |
|
|
<code class="filename">new</code>
|
19 |
|
|
</p></li><li class="listitem"><p>
|
20 |
|
|
<code class="filename">exception</code>
|
21 |
|
|
</p></li><li class="listitem"><p>
|
22 |
|
|
<code class="filename">typeinfo</code>
|
23 |
|
|
</p></li></ul></div><p>
|
24 |
|
|
In addition, throw in
|
25 |
|
|
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
|
26 |
|
|
<code class="filename">cxxabi.h</code>.
|
27 |
|
|
</p></li></ul></div><p>
|
28 |
|
|
In the
|
29 |
|
|
C++0x <a class="link" href="using.html#manual.intro.using.flags" title="Command Options">dialect</a> add
|
30 |
|
|
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
|
31 |
|
|
<code class="filename">initializer_list</code>
|
32 |
|
|
</p></li><li class="listitem"><p>
|
33 |
|
|
<code class="filename">type_traits</code>
|
34 |
|
|
</p></li></ul></div><p> There exists a library that offers runtime support for
|
35 |
|
|
just these headers, and it is called
|
36 |
|
|
<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 |
|
|
</p><p>
|
38 |
|
|
<span class="command"><strong>gcc foo.cc -lsupc++</strong></span>
|
39 |
|
|
</p><p>
|
40 |
|
|
No attempt is made to verify that only the minimal subset
|
41 |
|
|
identified above is actually used at compile time. Violations
|
42 |
|
|
are diagnosed as undefined symbols at link time.
|
43 |
|
|
</p></div><div class="sect2" title="Finding Dynamic or Shared Libraries"><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>
|
44 |
|
|
If the only library built is the static library
|
45 |
|
|
(<code class="filename">libstdc++.a</code>), or if
|
46 |
|
|
specifying static linking, this section is can be skipped. But
|
47 |
|
|
if building or using a shared library
|
48 |
|
|
(<code class="filename">libstdc++.so</code>), then
|
49 |
|
|
additional location information will need to be provided.
|
50 |
|
|
</p><p>
|
51 |
|
|
But how?
|
52 |
|
|
</p><p>
|
53 |
|
|
A quick read of the relevant part of the GCC
|
54 |
|
|
manual, <a class="ulink" href="http://gcc.gnu.org/onlinedocs/gcc/Invoking-G_002b_002b.html#Invoking-G_002b_002b" target="_top">Compiling
|
55 |
|
|
C++ Programs</a>, specifies linking against a C++
|
56 |
|
|
library. More details from the
|
57 |
|
|
GCC <a class="ulink" href="http://gcc.gnu.org/faq.html#rpath" target="_top">FAQ</a>,
|
58 |
|
|
which states <span class="emphasis"><em>GCC does not, by default, specify a
|
59 |
|
|
location so that the dynamic linker can find dynamic libraries at
|
60 |
|
|
runtime.</em></span>
|
61 |
|
|
</p><p>
|
62 |
|
|
Users will have to provide this information.
|
63 |
|
|
</p><p>
|
64 |
|
|
Methods vary for different platforms and different styles, and
|
65 |
|
|
are printed to the screen during installation. To summarize:
|
66 |
|
|
</p><div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem"><p>
|
67 |
|
|
At runtime set <code class="literal">LD_LIBRARY_PATH</code> in your
|
68 |
|
|
environment correctly, so that the shared library for
|
69 |
|
|
libstdc++ can be found and loaded. Be certain that you
|
70 |
|
|
understand all of the other implications and behavior
|
71 |
|
|
of <code class="literal">LD_LIBRARY_PATH</code> first.
|
72 |
|
|
</p></li><li class="listitem"><p>
|
73 |
|
|
Compile the path to find the library at runtime into the
|
74 |
|
|
program. This can be done by passing certain options to
|
75 |
|
|
<span class="command"><strong>g++</strong></span>, which will in turn pass them on to
|
76 |
|
|
the linker. The exact format of the options is dependent on
|
77 |
|
|
which linker you use:
|
78 |
|
|
</p><div class="itemizedlist"><ul class="itemizedlist" type="circle"><li class="listitem"><p>
|
79 |
|
|
GNU ld (default on Linux):<code class="literal">-Wl,--rpath,<code class="filename">destdir</code>/lib</code>
|
80 |
|
|
</p></li><li class="listitem"><p>
|
81 |
|
|
IRIX ld:<code class="literal">
|
82 |
|
|
-Wl,-rpath,<code class="filename">destdir</code>/lib</code>
|
83 |
|
|
</p></li><li class="listitem"><p>
|
84 |
|
|
Solaris ld:<code class="literal">-Wl,-R<code class="filename">destdir</code>/lib</code>
|
85 |
|
|
</p></li></ul></div></li></ul></div><p>
|
86 |
|
|
Use the <span class="command"><strong>ldd</strong></span> utility on the linked executable
|
87 |
|
|
to show
|
88 |
|
|
which <code class="filename">libstdc++.so</code>
|
89 |
|
|
library the system will get at runtime.
|
90 |
|
|
</p><p>
|
91 |
|
|
A <code class="filename">libstdc++.la</code> file is
|
92 |
|
|
also installed, for use with Libtool. If you use Libtool to
|
93 |
|
|
create your executables, these details are taken care of for
|
94 |
|
|
you.
|
95 |
|
|
</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="../spine.html">Home</a></td><td width="40%" align="right" valign="top"> Concurrency</td></tr></table></div></body></html>
|