1
<?xml version="1.0" encoding="utf-8" ?>
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" xml:lang="en" lang="en">
5
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
<meta name="generator" content="Docutils 0.5: http://docutils.sourceforge.net/" />
7
<title>libtorrent manual</title>
8
<meta name="author" content="Arvid Norberg, arvid@rasterbar.com" />
9
<link rel="stylesheet" href="style.css" type="text/css" />
12
<div class="document" id="libtorrent-manual">
13
<h1 class="title">libtorrent manual</h1>
14
<table class="docinfo" frame="void" rules="none">
15
<col class="docinfo-name" />
16
<col class="docinfo-content" />
18
<tr><th class="docinfo-name">Author:</th>
19
<td>Arvid Norberg, <a class="last reference external" href="mailto:arvid@rasterbar.com">arvid@rasterbar.com</a></td></tr>
22
<div class="contents topic" id="table-of-contents">
23
<p class="topic-title first">Table of contents</p>
25
<li><a class="reference internal" href="#downloading-and-building" id="id9">downloading and building</a><ul>
26
<li><a class="reference internal" href="#building-from-svn" id="id10">building from svn</a></li>
27
<li><a class="reference internal" href="#building-with-bbv2" id="id11">building with BBv2</a></li>
28
<li><a class="reference internal" href="#building-with-autotools" id="id12">building with autotools</a></li>
29
<li><a class="reference internal" href="#building-with-other-build-systems" id="id13">building with other build systems</a></li>
30
<li><a class="reference internal" href="#build-configurations" id="id14">build configurations</a></li>
35
<div class="section" id="downloading-and-building">
36
<h1>downloading and building</h1>
37
<p>To acquire the latest version of libtorrent, you'll have to grab it from SVN.
38
You'll find instructions on how to do this <a class="reference external" href="http://sourceforge.net/svn/?group_id=79942">here</a> (see subversion access).</p>
39
<p>The build systems supported "out of the box" in libtorrent are boost-build v2
40
(BBv2) and autotools (for unix-like systems). If you still can't build after
41
following these instructions, you can usually get help in the <tt class="docutils literal"><span class="pre">#libtorrent</span></tt>
42
IRC channel on <tt class="docutils literal"><span class="pre">irc.freenode.net</span></tt>.</p>
43
<p>Community contributed build tutorials can be found on the <a class="reference external" href="http://code.rasterbar.com/libtorrent/wiki/Building">wiki</a>.</p>
44
<div class="section" id="building-from-svn">
45
<h2>building from svn</h2>
46
<p>To build libtorrent from svn you need to check out the libtorrent sources from
47
sourceforge and also check out the asio sources from its sourceforge cvs.
48
If you downloaded a release tarball, you can skip this section.</p>
49
<p>To prepare the directory structure for building, follow these steps:</p>
51
<li>Check out libtorrent (<a class="reference external" href="http://sourceforge.net/svn/?group_id=79942">instructions</a>).</li>
52
<li>Check out asio (<a class="reference external" href="http://sourceforge.net/cvs/?group_id=122478">instructions</a>).</li>
53
<li>Copy the <tt class="docutils literal"><span class="pre">asio/include/asio/</span></tt> directory into the <tt class="docutils literal"><span class="pre">libtorrent/include/libtorrent/</span></tt>
54
directory. Alternatively you can make a symbolic link.</li>
55
<li>Copy <tt class="docutils literal"><span class="pre">asio/include/asio.hpp</span></tt> into <tt class="docutils literal"><span class="pre">libtorrent/include/libtorrent</span></tt>.</li>
57
<p>Now the libtorrent directory is ready for building. Follow the steps in one
58
of the following sections depending on which build system you prefer to use.</p>
60
<div class="section" id="building-with-bbv2">
61
<h2>building with BBv2</h2>
62
<p>The primary reason to use boost-build is that it will automatically build the
63
dependent boost libraries with the correct compiler settings, in order to
64
ensure that the build targets are link compatible (see <a class="reference external" href="http://boost.org/more/separate_compilation.html">boost guidelines</a>
65
for some details on this issue).</p>
66
<p>Since BBv2 will build the boost libraries for you, you need the full boost
67
source package. Having boost installed via some package system is usually not
68
enough (and even if it is enough, the necessary environment variables are
69
usually not set by the package installer).</p>
70
<p>If you want to build against an installed copy of boost, you can skip directly
71
to step 3 (assuming you also have boost build installed).</p>
72
<div class="section" id="step-1-download-boost">
73
<h3>Step 1: Download boost</h3>
74
<p>You'll find boost <a class="reference external" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041&release_id=376197">here</a>.</p>
75
<p>Extract the archive to some directory where you want it. For the sake of this
76
guide, let's assume you extract the package to <tt class="docutils literal"><span class="pre">c:\boost_1_34_0</span></tt> (I'm using
77
a windows path in this example since if you're on linux/unix you're more likely
78
to use the autotools). You'll need at least version 1.34 of the boost library
79
in order to build libtorrent.</p>
81
<div class="section" id="step-2-setup-bbv2">
82
<h3>Step 2: Setup BBv2</h3>
83
<p>First you need to build <tt class="docutils literal"><span class="pre">bjam</span></tt>. You do this by opening a terminal (In
84
windows, run <tt class="docutils literal"><span class="pre">cmd</span></tt>). Change directory to
85
<tt class="docutils literal"><span class="pre">c:\boost_1_34_0\tools\jam\src</span></tt>. Then run the script called
86
<tt class="docutils literal"><span class="pre">build.bat</span></tt> or <tt class="docutils literal"><span class="pre">build.sh</span></tt> on a unix system. This will build <tt class="docutils literal"><span class="pre">bjam</span></tt> and
87
place it in a directory starting with <tt class="docutils literal"><span class="pre">bin.</span></tt> and then have the name of your
88
platform. Copy the <tt class="docutils literal"><span class="pre">bjam.exe</span></tt> (or <tt class="docutils literal"><span class="pre">bjam</span></tt> on a unix system) to a place
89
that's in you shell's <tt class="docutils literal"><span class="pre">PATH</span></tt>. On linux systems a place commonly used may be
90
<tt class="docutils literal"><span class="pre">/usr/local/bin</span></tt> or on windows <tt class="docutils literal"><span class="pre">c:\windows</span></tt> (you can also add directories
91
to the search paths by modifying the environment variable called <tt class="docutils literal"><span class="pre">PATH</span></tt>).</p>
92
<p>Now you have <tt class="docutils literal"><span class="pre">bjam</span></tt> installed. <tt class="docutils literal"><span class="pre">bjam</span></tt> can be considered an interpreter
93
that the boost-build system is implemented on. So boost-build uses <tt class="docutils literal"><span class="pre">bjam</span></tt>.
94
So, to complete the installation you need to make two more things. You need to
95
set the environment variable <tt class="docutils literal"><span class="pre">BOOST_BUILD_PATH</span></tt>. This is the path that tells
96
<tt class="docutils literal"><span class="pre">bjam</span></tt> where it can find boost-build, your configuration file and all the
97
toolsets (descriptions used by boost-build to know how to use different
98
compilers on different platforms). Assuming the boost install path above, set
99
it to <tt class="docutils literal"><span class="pre">c:\boost_1_34_0\tools\build\v2</span></tt>.</p>
100
<p>To set an environment variable in windows, type for example:</p>
101
<pre class="literal-block">
102
set BOOST_BUILD_PATH=c:\boost_1_34_0\tools\build\v2
104
<p>In a terminal window.</p>
105
<p>The last thing to do to complete the setup of BBv2 is to modify your
106
<tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file. It is located in <tt class="docutils literal"><span class="pre">c:\boost_1_34_0\tools\build\v2</span></tt>.
107
Depending on your platform and which compiler you're using, you should add a
108
line for each compiler and compiler version you have installed on your system
109
that you want to be able to use with BBv2. For example, if you're using
110
Microsoft Visual Studio 7.1 (2003), just add a line:</p>
111
<pre class="literal-block">
114
<p>If you use GCC, add the line:</p>
115
<pre class="literal-block">
118
<p>If you have more than one version of GCC installed, you can add the
119
commandline used to invoke g++ after the version number, like this:</p>
120
<pre class="literal-block">
121
using gcc : 3.3 : g++-3.3 ;
122
using gcc : 4.0 : g++-4.0 ;
124
<p>Another toolset worth mentioning is the <tt class="docutils literal"><span class="pre">darwin</span></tt> toolset (For MacOS X).
125
From Tiger (10.4) MacOS X comes with both GCC 3.3 and GCC 4.0. Then you can
126
use the following toolsets:</p>
127
<pre class="literal-block">
128
using darwin : 3.3 : g++-3.3 ;
129
using darwin : 4.0 : g++-4.0 ;
131
<p>Note that the spaces around the semi-colons and colons are important!</p>
132
<p>Also see the <a class="reference external" href="http://www.boost.org/doc/html/bbv2/installation.html">official installation instructions</a>.</p>
134
<div class="section" id="step-3-building-libtorrent">
135
<h3>Step 3: Building libtorrent</h3>
136
<p>When building libtorrent, the <tt class="docutils literal"><span class="pre">Jamfile</span></tt> expects the environment variable
137
<tt class="docutils literal"><span class="pre">BOOST_ROOT</span></tt> to be set to the boost installation directory. It uses this to
138
find the boost libraries it depends on, so they can be built and their headers
139
files found. So, set this to <tt class="docutils literal"><span class="pre">c:\boost_1_34_0</span></tt>. You only need this if you're
140
building against a source distribution of boost.</p>
141
<p>Then the only thing left is simply to invoke <tt class="docutils literal"><span class="pre">bjam</span></tt>. If you want to specify
142
a specific toolset to use (compiler) you can just add that to the commandline.
144
<pre class="literal-block">
145
bjam msvc-7.1 boost=source
146
bjam gcc-3.3 boost=source
147
bjam darwin-4.0 boost=source
149
<p>If you're building against a system installed boost, specify <tt class="docutils literal"><span class="pre">boost=system</span></tt>.</p>
150
<p>To build different versions you can also just add the name of the build
151
variant. Some default build variants in BBv2 are <tt class="docutils literal"><span class="pre">release</span></tt>, <tt class="docutils literal"><span class="pre">debug</span></tt>,
152
<tt class="docutils literal"><span class="pre">profile</span></tt>.</p>
153
<p>You can build libtorrent as a dll too, by typing <tt class="docutils literal"><span class="pre">link=shared</span></tt>, or
154
<tt class="docutils literal"><span class="pre">link=static</span></tt> to build a static library.</p>
155
<p>If you want to explicitly say how to link against the runtime library, you
156
can set the <tt class="docutils literal"><span class="pre">runtime-link</span></tt> feature on the commandline, either to <tt class="docutils literal"><span class="pre">shared</span></tt>
157
or <tt class="docutils literal"><span class="pre">static</span></tt>. Most operating systems will only allow linking shared against
158
the runtime, but on windows you can do both. Example:</p>
159
<pre class="literal-block">
160
bjam msvc-7.1 link=static runtime-link=static boost=source
162
<div class="warning">
163
<p class="first admonition-title">Warning</p>
164
<p class="last">If you link statically to the runtime library, you cannot build libtorrent
165
as a shared library (DLL), since you will get separate heaps in the library
166
and in the client application. It will result in crashes and possibly link
169
<div class="warning">
170
<p class="first admonition-title">Warning</p>
171
<p class="last">With boost-build V2 (Milestone 11), the darwin toolset uses the <tt class="docutils literal"><span class="pre">-s</span></tt> linker
172
option to strip debug symbols. This option is buggy in Apple's GCC, and
173
will make the executable crash on startup. On Mac OS X, instead build
174
your release executables with the <tt class="docutils literal"><span class="pre">debug-symbols=on</span></tt> option, and
175
later strip your executable with <tt class="docutils literal"><span class="pre">strip</span></tt>.</p>
177
<div class="warning">
178
<p class="first admonition-title">Warning</p>
179
<p class="last">Some linux systems requires linking against <tt class="docutils literal"><span class="pre">librt</span></tt> in order to access
180
the POSIX clock functions. If you get an error complaining about a missing
181
symbol <tt class="docutils literal"><span class="pre">clock_gettime</span></tt>, you have to give <tt class="docutils literal"><span class="pre">need-librt=yes</span></tt> on the
182
bjam command line. This will make libtorrent link against <tt class="docutils literal"><span class="pre">librt</span></tt>.</p>
184
<p>The build targets are put in a directory called bin, and under it they are
185
sorted in directories depending on the toolset and build variant used.</p>
186
<p>To build the examples, just change directory to the examples directory and
187
invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> from there. To build and run the tests, go to the test
188
directory and run <tt class="docutils literal"><span class="pre">bjam</span></tt>.</p>
189
<p>Note that if you're building on windows using the <tt class="docutils literal"><span class="pre">msvc</span></tt> toolset, you cannot run it
190
from a cygwin terminal, you'll have to run it from a <tt class="docutils literal"><span class="pre">cmd</span></tt> terminal. The same goes for
191
cygwin, if you're building with gcc in cygwin you'll have to run it from a cygwin terminal.
192
Also, make sure the paths are correct in the different environments. In cygwin, the paths
193
(<tt class="docutils literal"><span class="pre">BOOST_BUILD_PATH</span></tt> and <tt class="docutils literal"><span class="pre">BOOST_ROOT</span></tt>) should be in the typical unix-format (e.g.
194
<tt class="docutils literal"><span class="pre">/cygdrive/c/boost_1_34_0</span></tt>). In the windows environment, they should have the typical
195
windows format (<tt class="docutils literal"><span class="pre">c:/boost_1_34_0</span></tt>).</p>
196
<p>The <tt class="docutils literal"><span class="pre">Jamfile</span></tt> will define <tt class="docutils literal"><span class="pre">NDEBUG</span></tt> when it's building a release build.
197
For more build configuration flags see <a class="reference internal" href="#build-configurations">Build configurations</a>.</p>
198
<p>Build features:</p>
199
<table border="1" class="docutils">
204
<thead valign="bottom">
205
<tr><th class="head">boost build feature</th>
206
<th class="head">values</th>
210
<tr><td><tt class="docutils literal"><span class="pre">boost</span></tt></td>
211
<td><ul class="first last simple">
212
<li><tt class="docutils literal"><span class="pre">system</span></tt> - default. Tells the Jamfile that
213
boost is installed and should be linked against
214
the system libraries.</li>
215
<li><tt class="docutils literal"><span class="pre">source</span></tt> - Specifies that boost is to be built
216
from source. The environment variable
217
<tt class="docutils literal"><span class="pre">BOOST_ROOT</span></tt> must be defined to point to the
218
boost directory.</li>
222
<tr><td><tt class="docutils literal"><span class="pre">logging</span></tt></td>
223
<td><ul class="first last simple">
224
<li><tt class="docutils literal"><span class="pre">none</span></tt> - no logging.</li>
225
<li><tt class="docutils literal"><span class="pre">default</span></tt> - basic session logging.</li>
226
<li><tt class="docutils literal"><span class="pre">verbose</span></tt> - verbose peer wire logging.</li>
230
<tr><td><tt class="docutils literal"><span class="pre">dht-support</span></tt></td>
231
<td><ul class="first last simple">
232
<li><tt class="docutils literal"><span class="pre">on</span></tt> - build with support for tracker less
233
torrents and DHT support.</li>
234
<li><tt class="docutils literal"><span class="pre">logging</span></tt> - build with DHT support and verbose
235
logging of the DHT protocol traffic.</li>
236
<li><tt class="docutils literal"><span class="pre">off</span></tt> - build without DHT support.</li>
240
<tr><td><tt class="docutils literal"><span class="pre">need-librt</span></tt></td>
241
<td><ul class="first last simple">
242
<li><tt class="docutils literal"><span class="pre">no</span></tt> - this platform does not need to link
243
against librt to have POSIX time functions.</li>
244
<li><tt class="docutils literal"><span class="pre">yes</span></tt> - specify this if your linux system
245
requires you to link against librt.a. This is
246
typically the case on x86 64 bit systems.</li>
250
<tr><td><tt class="docutils literal"><span class="pre">zlib</span></tt></td>
251
<td><ul class="first last simple">
252
<li><tt class="docutils literal"><span class="pre">system</span></tt> - links against the zlib supplied
253
with your operating system.</li>
254
<li><tt class="docutils literal"><span class="pre">shipped</span></tt> - links against the zlib bundled
255
with the libtorrent package.</li>
259
<tr><td><tt class="docutils literal"><span class="pre">upnp-logging</span></tt></td>
260
<td><ul class="first last simple">
261
<li><tt class="docutils literal"><span class="pre">off</span></tt> - default. Does not log UPnP traffic.</li>
262
<li><tt class="docutils literal"><span class="pre">on</span></tt> - creates "upnp.log" with the messages
263
sent to and received from UPnP devices.</li>
267
<tr><td><tt class="docutils literal"><span class="pre">openssl</span></tt></td>
268
<td><ul class="first last simple">
269
<li><tt class="docutils literal"><span class="pre">pe</span></tt> - turns on support for encrypted
270
connections. requires openssl (libcrypto)</li>
271
<li><tt class="docutils literal"><span class="pre">sha-1</span></tt> - openssl will be used instead of the
272
public domain SHA-1 implementation shipped with
273
libtorrent. <tt class="docutils literal"><span class="pre">libcrypto.a</span></tt> will be required for
274
linking. Encryption support is still turned off.</li>
275
<li><tt class="docutils literal"><span class="pre">off</span></tt> - turns off support for encrypted
276
connections. openssl is not linked in. The
277
shipped public domain SHA-1 implementation is
282
<tr><td><tt class="docutils literal"><span class="pre">link</span></tt></td>
283
<td><ul class="first last simple">
284
<li><tt class="docutils literal"><span class="pre">static</span></tt> - builds libtorrent as a static
285
library (.a / .lib)</li>
286
<li><tt class="docutils literal"><span class="pre">shared</span></tt> - builds libtorrent as a shared
287
library (.so / .dll).</li>
291
<tr><td><tt class="docutils literal"><span class="pre">runtime-link</span></tt></td>
292
<td><ul class="first last simple">
293
<li><tt class="docutils literal"><span class="pre">static</span></tt> - links statically against the
294
run-time library (if available on your
296
<li><tt class="docutils literal"><span class="pre">shared</span></tt> - link dynamically against the
297
run-time library (default).</li>
301
<tr><td><tt class="docutils literal"><span class="pre">variant</span></tt></td>
302
<td><ul class="first last simple">
303
<li><tt class="docutils literal"><span class="pre">debug</span></tt> - builds libtorrent with debug
304
information and invariant checks.</li>
305
<li><tt class="docutils literal"><span class="pre">release</span></tt> - builds libtorrent in release mode
306
without invariant checks and with optimization.</li>
307
<li><tt class="docutils literal"><span class="pre">profile</span></tt> - builds libtorrent with profile
312
<tr><td><tt class="docutils literal"><span class="pre">character-set</span></tt></td>
313
<td><p class="first">This setting will only have an affect on windows.
314
Other platforms are expected to support UTF-8.</p>
315
<ul class="last simple">
316
<li><tt class="docutils literal"><span class="pre">ansi</span></tt> - The ansi version of the win32 API is
318
<li><tt class="docutils literal"><span class="pre">unicode</span></tt> - The unicode version of the win32
323
<tr><td><tt class="docutils literal"><span class="pre">invariant-checks</span></tt></td>
324
<td><p class="first">This setting only affects debug builds (where
325
<tt class="docutils literal"><span class="pre">NDEBUG</span></tt> is not defined). It defaults to <tt class="docutils literal"><span class="pre">on</span></tt>.</p>
326
<ul class="last simple">
327
<li><tt class="docutils literal"><span class="pre">on</span></tt> - internal invariant checks are enabled.</li>
328
<li><tt class="docutils literal"><span class="pre">off</span></tt> - internal invariant checks are
329
disabled. The resulting executable will run
330
faster than a regular debug build.</li>
334
<tr><td><tt class="docutils literal"><span class="pre">debug-symbols</span></tt></td>
335
<td><ul class="first last simple">
336
<li><tt class="docutils literal"><span class="pre">on</span></tt> - default for debug builds. This setting
337
is useful for building release builds with
339
<li><tt class="docutils literal"><span class="pre">off</span></tt> - default for release builds.</li>
345
<p>The <tt class="docutils literal"><span class="pre">variant</span></tt> feature is <em>implicit</em>, which means you don't need to specify
346
the name of the feature, just the value.</p>
347
<p>The logs created when building vlog or log mode are put in a directory called
348
<tt class="docutils literal"><span class="pre">libtorrent_logs</span></tt> in the current working directory.</p>
349
<p>When building the example client on windows, you need to build with
350
<tt class="docutils literal"><span class="pre">link=static</span></tt> otherwise you may get unresolved external symbols for some
351
boost.program-options symbols.</p>
352
<p>For more information, see the <a class="reference external" href="http://www.boost.org/tools/build/v2/index.html">Boost build v2 documentation</a>, or more
353
specifically <a class="reference external" href="http://www.boost.org/doc/html/bbv2/reference.html#bbv2.advanced.builtins.features">the section on builtin features</a>.</p>
356
<div class="section" id="building-with-autotools">
357
<h2>building with autotools</h2>
358
<p>First of all, you need to install <tt class="docutils literal"><span class="pre">automake</span></tt> and <tt class="docutils literal"><span class="pre">autoconf</span></tt>. Many
359
unix/linux systems comes with these preinstalled.</p>
360
<p>The prerequisites for building libtorrent is boost.thread, boost.date_time
361
and boost.filesystem. Those are the <em>compiled</em> boost libraries needed. The
362
headers-only libraries needed include (but is not necessarily limited to)
363
boost.bind, boost.ref, boost.multi_index, boost.optional, boost.lexical_cast,
364
boost.integer, boost.iterator, boost.tuple, boost.array, boost.function,
365
boost.smart_ptr, boost.preprocessor, boost.static_assert.</p>
366
<p>If you want to build the <tt class="docutils literal"><span class="pre">client_test</span></tt> example, you'll also need boost.regex
367
and boost.program_options.</p>
368
<div class="section" id="step-1-generating-the-build-system">
369
<h3>Step 1: Generating the build system</h3>
370
<p>No build system is present if libtorrent is checked out from CVS - it
371
needs to be generated first. If you're building from a released tarball,
372
you may skip directly to <a class="reference internal" href="#step-2-running-configure">Step 2: Running configure</a>.</p>
373
<p>Execute the following commands, in the given order, to generate
374
the build system:</p>
375
<pre class="literal-block">
378
libtoolize --copy --force
379
automake --add-missing --copy --gnu
382
<p>On darwin/OSX you have to run <tt class="docutils literal"><span class="pre">glibtoolize</span></tt> instead of <tt class="docutils literal"><span class="pre">libtoolize</span></tt>.</p>
384
<div class="section" id="step-2-running-configure">
385
<h3>Step 2: Running configure</h3>
386
<p>In your shell, change directory to the libtorrent directory and run
387
<tt class="docutils literal"><span class="pre">./configure</span></tt>. This will look for libraries and C++ features that libtorrent
388
is dependent on. If something is missing or can't be found it will print an
389
error telling you what failed.</p>
390
<p>The most likely problem you may encounter is that the configure script won't
391
find the boost libraries. Make sure you have boost installed on your system.
392
The easiest way to install boost is usually to use the preferred package
393
system on your platform. Usually libraries and headers are installed in
394
standard directories where the compiler will find them, but sometimes that
395
may not be the case. For example when installing boost on darwin using
396
darwinports (the package system based on BSD ports) all libraries are
397
installed to <tt class="docutils literal"><span class="pre">/opt/local/lib</span></tt> and headers are installed to
398
<tt class="docutils literal"><span class="pre">/opt/local/include</span></tt>. By default the compiler will not look in these
399
directories. You have to set the enviornment variables <tt class="docutils literal"><span class="pre">LDFLAGS</span></tt> and
400
<tt class="docutils literal"><span class="pre">CXXFLAGS</span></tt> in order to make the compiler find those libs. In this example
401
you'd set them like this:</p>
402
<pre class="literal-block">
403
export LDFLAGS=-L/opt/local/lib
404
export CXXFLAGS=-I/opt/local/include
406
<p>It was observed on FreeBSD (release 6.0) that one needs to add '-lpthread' to
407
LDFLAGS, as Boost::Thread detection will fail without it, even if
408
Boost::Thread is installed.</p>
409
<p>If you need to set these variables, it may be a good idea to add those lines
410
to your <tt class="docutils literal"><span class="pre">~/.profile</span></tt> or <tt class="docutils literal"><span class="pre">~/.tcshrc</span></tt> depending on your shell.</p>
411
<p>If the boost libraries are named with a suffix on your platform, you may use
412
the <tt class="docutils literal"><span class="pre">--with-boost-thread=</span></tt> option to specify the suffix used for the thread
413
library in this case. For more information about these options, run:</p>
414
<pre class="literal-block">
417
<p>On gentoo the boost libraries that are built with multi-threading support have
418
the suffix <tt class="docutils literal"><span class="pre">mt</span></tt>.</p>
419
<p>You know that the boost libraries were found if you see the following output
420
from the configure script:</p>
421
<pre class="literal-block">
422
checking whether the Boost::DateTime library is available... yes
423
checking for main in -lboost_date_time... yes
424
checking whether the Boost::Filesystem library is available... yes
425
checking for main in -lboost_filesystem... yes
426
checking whether the Boost::Thread library is available... yes
427
checking for main in -lboost_thread... yes
429
<p>Another possible source of problems may be if the path to your libtorrent
430
directory contains spaces. Make sure you either rename the directories with
431
spaces in their names to remove the spaces or move the libtorrent directory.</p>
433
<div class="section" id="creating-a-debug-build">
434
<h3>Creating a debug build</h3>
435
<p>To tell configure to build a debug version (with debug info, asserts
436
and invariant checks enabled), you have to run the configure script
437
with the following option:</p>
438
<pre class="literal-block">
439
./configure --enable-debug=yes
442
<div class="section" id="creating-a-release-build">
443
<h3>Creating a release build</h3>
444
<p>To tell the configure to build a release version (without debug info,
445
asserts and invariant checks), you have to run the configure script
446
with the following option:</p>
447
<pre class="literal-block">
448
./configure --enable-debug=no
450
<p>The above option make use of -DNDEBUG, which is used throughout libtorrent.</p>
452
<div class="section" id="id8">
453
<h3>Step 3: Building libtorrent</h3>
454
<p>Once the configure script is run successfully, you just type <tt class="docutils literal"><span class="pre">make</span></tt> and
455
libtorrent, the examples and the tests will be built.</p>
456
<p>When libtorrent is built it may be a good idea to run the tests, you do this
457
by running <tt class="docutils literal"><span class="pre">make</span> <span class="pre">check</span></tt>.</p>
458
<p>If you want to build a release version (without debug info, asserts and
459
invariant checks), you have to rerun the configure script and rebuild, like this:</p>
460
<pre class="literal-block">
461
./configure --disable-debug
467
<div class="section" id="building-with-other-build-systems">
468
<h2>building with other build systems</h2>
469
<p>If you're making your own project file, note that there are two versions of
470
the file abstraction. There's one <tt class="docutils literal"><span class="pre">file_win.cpp</span></tt> which relies on windows
471
file API that supports files larger than 2 Gigabytes. This does not work in
472
vc6 for some reason, possibly because it may require windows NT and above.
473
The other file, <tt class="docutils literal"><span class="pre">file.cpp</span></tt> is the default implementation that simply relies
474
on the standard low level io routines (<tt class="docutils literal"><span class="pre">read()</span></tt>, <tt class="docutils literal"><span class="pre">write()</span></tt>, <tt class="docutils literal"><span class="pre">open()</span></tt>
475
etc.), this implementation doesn't do anything special to support unicode
476
filenames, so if your target is Windows 2000 and up, you may want to use
477
<tt class="docutils literal"><span class="pre">file_win.cpp</span></tt> which supports unicode filenames.</p>
478
<p>If you're building in MS Visual Studio, you may have to set the compiler
479
options "force conformance in for loop scope", "treat wchar_t as built-in
480
type" and "Enable Run-Time Type Info" to Yes. For a detailed description
481
on how to build libtorrent with VS, see <a class="reference external" href="http://code.rasterbar.com/libtorrent/wiki/Building">the wiki</a>.</p>
483
<div class="section" id="build-configurations">
484
<h2>build configurations</h2>
485
<p>By default libtorrent is built In debug mode, and will have pretty expensive
486
invariant checks and asserts built into it. If you want to disable such checks
487
(you want to do that in a release build) you can see the table below for which
488
defines you can use to control the build.</p>
489
<table border="1" class="docutils">
494
<thead valign="bottom">
495
<tr><th class="head">macro</th>
496
<th class="head">description</th>
500
<tr><td><tt class="docutils literal"><span class="pre">NDEBUG</span></tt></td>
501
<td>If you define this macro, all asserts,
502
invariant checks and general debug code will be
503
removed. Since there is quite a lot of code in
504
in header files in libtorrent, it may be
505
important to define the symbol consistently
506
across compilation units, including the clients
507
files. Potential problems is different
508
compilation units having different views of
509
structs and class layouts and sizes.</td>
511
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_LOGGING</span></tt></td>
512
<td>This macro will enable logging of the session
513
events, such as tracker announces and incoming
514
connections (as well as blocked connections).</td>
516
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_VERBOSE_LOGGING</span></tt></td>
517
<td>If you define this macro, every peer connection
518
will log its traffic to a log file as well as
519
the session log.</td>
521
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_STORAGE_DEBUG</span></tt></td>
522
<td>This will enable extra expensive invariant
523
checks in the storage, including logging of
526
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_UPNP_LOGGING</span></tt></td>
527
<td>Generates a "upnp.log" file with the UPnP
528
traffic. This is very useful when debugging
529
support for various UPnP routers.
530
support for various UPnP routers.</td>
532
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISK_STATS</span></tt></td>
533
<td>This will create a log of all disk activity
534
which later can parsed and graphed using
535
<tt class="docutils literal"><span class="pre">parse_disk_log.py</span></tt>.</td>
537
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_STATS</span></tt></td>
538
<td>This will generate a log with transfer rates,
539
downloading torrents, seeding torrents, peers,
540
connecting peers and disk buffers in use. The
541
log can be parsed and graphed with
542
<tt class="docutils literal"><span class="pre">parse_session_stats.py</span></tt>.</td>
544
<tr><td><tt class="docutils literal"><span class="pre">UNICODE</span></tt></td>
545
<td>If building on windows this will make sure the
546
UTF-8 strings in pathnames are converted into
547
UTF-16 before they are passed to the file
550
<tr><td><tt class="docutils literal"><span class="pre">LITTLE_ENDIAN</span></tt></td>
551
<td>This will use the little endian version of the
552
sha-1 code. If defined on a big-endian system
553
the sha-1 hashes will be incorrect and fail.
554
If it is not defined and <tt class="docutils literal"><span class="pre">__BIG_ENDIAN__</span></tt>
555
isn't defined either (it is defined by Apple's
556
GCC) both little-endian and big-endian versions
557
will be built and the correct code will be
558
chosen at run-time.</td>
560
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_LINKING_SHARED</span></tt></td>
561
<td>If this is defined when including the
562
libtorrent headers, the classes and functions
563
will be tagged with <tt class="docutils literal"><span class="pre">__declspec(dllimport)</span></tt>
564
on msvc and default visibility on GCC 4 and
565
later. Set this in your project if you're
566
linking against libtorrent as a shared library.
567
(This is set by the Jamfile when
568
<tt class="docutils literal"><span class="pre">link=shared</span></tt> is set).</td>
570
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_BUILDING_SHARED</span></tt></td>
571
<td>If this is defined, the functions and classes
572
in libtorrent are marked with
573
<tt class="docutils literal"><span class="pre">__declspec(dllexport)</span></tt> on msvc, or with
574
default visibility on GCC 4 and later. This
575
should be defined when building libtorrent as
576
a shared library. (This is set by the Jamfile
577
when <tt class="docutils literal"><span class="pre">link=shared</span></tt> is set).</td>
579
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_DHT</span></tt></td>
580
<td>If this is defined, the support for trackerless
581
torrents will be disabled.</td>
583
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_DHT_VERBOSE_LOGGING</span></tt></td>
584
<td>This will enable verbose logging of the DHT
585
protocol traffic.</td>
587
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_ENCRYPTION</span></tt></td>
588
<td>This will disable any encryption support and
589
the openssl dependency that comes with it.
590
Encryption support is the peer connection
591
encrypted supported by clients such as
592
uTorrent, Azureus and KTorrent.</td>
594
<tr><td><tt class="docutils literal"><span class="pre">_UNICODE</span></tt></td>
595
<td>On windows, this will cause the file IO
596
use wide character API, to properly support
597
non-ansi characters.</td>
599
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_RESOLVE_COUNTRIES</span></tt></td>
600
<td>Defining this will disable the ability to
601
resolve countries of origin for peer IPs.</td>
603
<tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_INVARIANT_CHECKS</span></tt></td>
604
<td>This will disable internal invariant checks in
605
libtorrent. The invariant checks can sometime
606
be quite expensive, they typically don't scale
607
very well. This option can be used to still
608
build in debug mode, with asserts enabled, but
609
make the resulting executable faster.</td>
613
<p>If you experience that libtorrent uses unreasonable amounts of cpu, it will
614
definitely help to define <tt class="docutils literal"><span class="pre">NDEBUG</span></tt>, since it will remove the invariant checks
615
within the library.</p>