default to use UNICODE on windows
[libtorrent.git] / docs / building.html
blob19cc07b7990c7ec95132cee0d620795b4c4c7391
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">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 <meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
7 <title>libtorrent manual</title>
8 <meta name="author" content="Arvid Norberg, arvid&#64;rasterbar.com" />
9 <link rel="stylesheet" href="style.css" type="text/css" />
10 </head>
11 <body>
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" />
17 <tbody valign="top">
18 <tr><th class="docinfo-name">Author:</th>
19 <td>Arvid Norberg, <a class="last reference" href="mailto:arvid&#64;rasterbar.com">arvid&#64;rasterbar.com</a></td></tr>
20 </tbody>
21 </table>
22 <div class="contents topic" id="table-of-contents">
23 <p class="topic-title first"><a name="table-of-contents">Table of contents</a></p>
24 <ul class="simple">
25 <li><a class="reference" href="#downloading-and-building" id="id9" name="id9">downloading and building</a><ul>
26 <li><a class="reference" href="#building-from-svn" id="id10" name="id10">building from svn</a></li>
27 <li><a class="reference" href="#building-with-bbv2" id="id11" name="id11">building with BBv2</a></li>
28 <li><a class="reference" href="#building-with-autotools" id="id12" name="id12">building with autotools</a></li>
29 <li><a class="reference" href="#building-with-other-build-systems" id="id13" name="id13">building with other build systems</a></li>
30 <li><a class="reference" href="#build-configurations" id="id14" name="id14">build configurations</a></li>
31 </ul>
32 </li>
33 </ul>
34 </div>
35 <div class="section">
36 <h1><a id="downloading-and-building" name="downloading-and-building">downloading and building</a></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" href="http://sourceforge.net/svn/?group_id=79942">here</a> (see subversion access).</p>
39 <p>The build systems supported &quot;out of the box&quot; 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" href="http://code.rasterbar.com/libtorrent/wiki/Building">wiki</a>.</p>
44 <div class="section">
45 <h2><a id="building-from-svn" name="building-from-svn">building from svn</a></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>
50 <ul class="simple">
51 <li>Check out libtorrent (<a class="reference" href="http://sourceforge.net/svn/?group_id=79942">instructions</a>).</li>
52 <li>Check out asio (<a class="reference" 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>
56 </ul>
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>
59 </div>
60 <div class="section">
61 <h2><a id="building-with-bbv2" name="building-with-bbv2">building with BBv2</a></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" 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">
73 <h3><a id="step-1-download-boost" name="step-1-download-boost">Step 1: Download boost</a></h3>
74 <p>You'll find boost <a class="reference" href="http://sourceforge.net/project/showfiles.php?group_id=7586&amp;package_id=8041&amp;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>
80 </div>
81 <div class="section">
82 <h3><a id="step-2-setup-bbv2" name="step-2-setup-bbv2">Step 2: Setup BBv2</a></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
103 </pre>
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">
112 using msvc : 7.1 ;
113 </pre>
114 <p>If you use GCC, add the line:</p>
115 <pre class="literal-block">
116 using gcc ;
117 </pre>
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 ;
123 </pre>
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 ;
130 </pre>
131 <p>Note that the spaces around the semi-colons and colons are important!</p>
132 <p>Also see the <a class="reference" href="http://www.boost.org/doc/html/bbv2/installation.html">official installation instructions</a>.</p>
133 </div>
134 <div class="section">
135 <h3><a id="step-3-building-libtorrent" name="step-3-building-libtorrent">Step 3: Building libtorrent</a></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.
143 For example:</p>
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
148 </pre>
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
161 </pre>
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
167 errors.</p>
168 </div>
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>
176 </div>
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>
183 </div>
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" href="#build-configurations">Build configurations</a>.</p>
198 <p>Build features:</p>
199 <table border="1" class="docutils">
200 <colgroup>
201 <col width="32%" />
202 <col width="68%" />
203 </colgroup>
204 <thead valign="bottom">
205 <tr><th class="head">boost build feature</th>
206 <th class="head">values</th>
207 </tr>
208 </thead>
209 <tbody valign="top">
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>
219 </ul>
220 </td>
221 </tr>
222 <tr><td><tt class="docutils literal"><span class="pre">boost-link</span></tt></td>
223 <td><ul class="first last simple">
224 <li><tt class="docutils literal"><span class="pre">static</span></tt> - links statically against the boost
225 libraries.</li>
226 <li><tt class="docutils literal"><span class="pre">shared</span></tt> - links dynamically against the boost
227 libraries.</li>
228 </ul>
229 </td>
230 </tr>
231 <tr><td><tt class="docutils literal"><span class="pre">logging</span></tt></td>
232 <td><ul class="first last simple">
233 <li><tt class="docutils literal"><span class="pre">none</span></tt> - no logging.</li>
234 <li><tt class="docutils literal"><span class="pre">default</span></tt> - basic session logging.</li>
235 <li><tt class="docutils literal"><span class="pre">verbose</span></tt> - verbose peer wire logging.</li>
236 <li><tt class="docutils literal"><span class="pre">errors</span></tt> - like verbose, but limited to errors.</li>
237 </ul>
238 </td>
239 </tr>
240 <tr><td><tt class="docutils literal"><span class="pre">dht-support</span></tt></td>
241 <td><ul class="first last simple">
242 <li><tt class="docutils literal"><span class="pre">on</span></tt> - build with support for tracker less
243 torrents and DHT support.</li>
244 <li><tt class="docutils literal"><span class="pre">logging</span></tt> - build with DHT support and verbose
245 logging of the DHT protocol traffic.</li>
246 <li><tt class="docutils literal"><span class="pre">off</span></tt> - build without DHT support.</li>
247 </ul>
248 </td>
249 </tr>
250 <tr><td><tt class="docutils literal"><span class="pre">need-librt</span></tt></td>
251 <td><ul class="first last simple">
252 <li><tt class="docutils literal"><span class="pre">no</span></tt> - this platform does not need to link
253 against librt to have POSIX time functions.</li>
254 <li><tt class="docutils literal"><span class="pre">yes</span></tt> - specify this if your linux system
255 requires you to link against librt.a. This is
256 typically the case on x86 64 bit systems.</li>
257 </ul>
258 </td>
259 </tr>
260 <tr><td><tt class="docutils literal"><span class="pre">zlib</span></tt></td>
261 <td><ul class="first last simple">
262 <li><tt class="docutils literal"><span class="pre">system</span></tt> - links against the zlib supplied
263 with your operating system.</li>
264 <li><tt class="docutils literal"><span class="pre">shipped</span></tt> - links against the zlib bundled
265 with the libtorrent package.</li>
266 </ul>
267 </td>
268 </tr>
269 <tr><td><tt class="docutils literal"><span class="pre">geoip</span></tt></td>
270 <td><ul class="first last simple">
271 <li><tt class="docutils literal"><span class="pre">off</span></tt> - geo ip lookups disabled</li>
272 <li><tt class="docutils literal"><span class="pre">static</span></tt> - <a class="reference" href="http://www.maxmind.com/app/api">MaxMind</a> geo ip lookup code linked
273 in statically. Note that this code is under
274 LGPL license.</li>
275 <li><tt class="docutils literal"><span class="pre">shared</span></tt> - The <a class="reference" href="http://www.maxmind.com/app/api">MaxMind</a> geo ip lookup library
276 is expected to be installed on the system and
277 it will be used.</li>
278 </ul>
279 </td>
280 </tr>
281 <tr><td><tt class="docutils literal"><span class="pre">upnp-logging</span></tt></td>
282 <td><ul class="first last simple">
283 <li><tt class="docutils literal"><span class="pre">off</span></tt> - default. Does not log UPnP traffic.</li>
284 <li><tt class="docutils literal"><span class="pre">on</span></tt> - creates &quot;upnp.log&quot; with the messages
285 sent to and received from UPnP devices.</li>
286 </ul>
287 </td>
288 </tr>
289 <tr><td><tt class="docutils literal"><span class="pre">openssl</span></tt></td>
290 <td><ul class="first last simple">
291 <li><tt class="docutils literal"><span class="pre">pe</span></tt> - turns on support for encrypted
292 connections. requires openssl (libcrypto)</li>
293 <li><tt class="docutils literal"><span class="pre">sha-1</span></tt> - openssl will be used instead of the
294 public domain SHA-1 implementation shipped with
295 libtorrent. <tt class="docutils literal"><span class="pre">libcrypto.a</span></tt> will be required for
296 linking. Encryption support is still turned off.</li>
297 <li><tt class="docutils literal"><span class="pre">off</span></tt> - turns off support for encrypted
298 connections. openssl is not linked in. The
299 shipped public domain SHA-1 implementation is
300 used.</li>
301 </ul>
302 </td>
303 </tr>
304 <tr><td><tt class="docutils literal"><span class="pre">pool-allocators</span></tt></td>
305 <td><ul class="first last simple">
306 <li><tt class="docutils literal"><span class="pre">on</span></tt> - default, uses pool allocators for send
307 buffers.</li>
308 <li><tt class="docutils literal"><span class="pre">off</span></tt> - uses <tt class="docutils literal"><span class="pre">malloc()</span></tt> and <tt class="docutils literal"><span class="pre">free()</span></tt>
309 instead. Might be useful to debug buffer issues
310 with tools like electric fence or libgmalloc.</li>
311 </ul>
312 </td>
313 </tr>
314 <tr><td><tt class="docutils literal"><span class="pre">link</span></tt></td>
315 <td><ul class="first last simple">
316 <li><tt class="docutils literal"><span class="pre">static</span></tt> - builds libtorrent as a static
317 library (.a / .lib)</li>
318 <li><tt class="docutils literal"><span class="pre">shared</span></tt> - builds libtorrent as a shared
319 library (.so / .dll).</li>
320 </ul>
321 </td>
322 </tr>
323 <tr><td><tt class="docutils literal"><span class="pre">runtime-link</span></tt></td>
324 <td><ul class="first last simple">
325 <li><tt class="docutils literal"><span class="pre">static</span></tt> - links statically against the
326 run-time library (if available on your
327 platform).</li>
328 <li><tt class="docutils literal"><span class="pre">shared</span></tt> - link dynamically against the
329 run-time library (default).</li>
330 </ul>
331 </td>
332 </tr>
333 <tr><td><tt class="docutils literal"><span class="pre">variant</span></tt></td>
334 <td><ul class="first last simple">
335 <li><tt class="docutils literal"><span class="pre">debug</span></tt> - builds libtorrent with debug
336 information and invariant checks.</li>
337 <li><tt class="docutils literal"><span class="pre">release</span></tt> - builds libtorrent in release mode
338 without invariant checks and with optimization.</li>
339 <li><tt class="docutils literal"><span class="pre">profile</span></tt> - builds libtorrent with profile
340 information.</li>
341 </ul>
342 </td>
343 </tr>
344 <tr><td><tt class="docutils literal"><span class="pre">character-set</span></tt></td>
345 <td><p class="first">This setting will only have an affect on windows.
346 Other platforms are expected to support UTF-8.</p>
347 <ul class="last simple">
348 <li><tt class="docutils literal"><span class="pre">unicode</span></tt> - The unicode version of the win32
349 API is used. This is default.</li>
350 <li><tt class="docutils literal"><span class="pre">ansi</span></tt> - The ansi version of the win32 API is
351 used.</li>
352 </ul>
353 </td>
354 </tr>
355 <tr><td><tt class="docutils literal"><span class="pre">invariant-checks</span></tt></td>
356 <td><p class="first">This setting only affects debug builds (where
357 <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>
358 <ul class="last simple">
359 <li><tt class="docutils literal"><span class="pre">on</span></tt> - internal invariant checks are enabled.</li>
360 <li><tt class="docutils literal"><span class="pre">off</span></tt> - internal invariant checks are
361 disabled. The resulting executable will run
362 faster than a regular debug build.</li>
363 <li><tt class="docutils literal"><span class="pre">full</span></tt> - turns on extra expensive invariant
364 checks.</li>
365 </ul>
366 </td>
367 </tr>
368 <tr><td><tt class="docutils literal"><span class="pre">debug-symbols</span></tt></td>
369 <td><ul class="first last simple">
370 <li><tt class="docutils literal"><span class="pre">on</span></tt> - default for debug builds. This setting
371 is useful for building release builds with
372 symbols.</li>
373 <li><tt class="docutils literal"><span class="pre">off</span></tt> - default for release builds.</li>
374 </ul>
375 </td>
376 </tr>
377 </tbody>
378 </table>
379 <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
380 the name of the feature, just the value.</p>
381 <p>The logs created when building vlog or log mode are put in a directory called
382 <tt class="docutils literal"><span class="pre">libtorrent_logs</span></tt> in the current working directory.</p>
383 <p>When building the example client on windows, you need to build with
384 <tt class="docutils literal"><span class="pre">link=static</span></tt> otherwise you may get unresolved external symbols for some
385 boost.program-options symbols.</p>
386 <p>For more information, see the <a class="reference" href="http://www.boost.org/tools/build/v2/index.html">Boost build v2 documentation</a>, or more
387 specifically <a class="reference" href="http://www.boost.org/doc/html/bbv2/reference.html#bbv2.advanced.builtins.features">the section on builtin features</a>.</p>
388 </div>
389 </div>
390 <div class="section">
391 <h2><a id="building-with-autotools" name="building-with-autotools">building with autotools</a></h2>
392 <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
393 unix/linux systems comes with these preinstalled.</p>
394 <p>The prerequisites for building libtorrent are boost.thread, boost.date_time
395 and boost.filesystem. Those are the <em>compiled</em> boost libraries needed. The
396 headers-only libraries needed include (but is not necessarily limited to)
397 boost.bind, boost.ref, boost.multi_index, boost.optional, boost.lexical_cast,
398 boost.integer, boost.iterator, boost.tuple, boost.array, boost.function,
399 boost.smart_ptr, boost.preprocessor, boost.static_assert.</p>
400 <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
401 and boost.program_options.</p>
402 <div class="section">
403 <h3><a id="step-1-generating-the-build-system" name="step-1-generating-the-build-system">Step 1: Generating the build system</a></h3>
404 <p>No build system is present if libtorrent is checked out from CVS - it
405 needs to be generated first. If you're building from a released tarball,
406 you may skip directly to <a class="reference" href="#step-2-running-configure">Step 2: Running configure</a>.</p>
407 <p>Execute the following commands, in the given order, to generate
408 the build system:</p>
409 <pre class="literal-block">
410 aclocal -I m4
411 autoheader
412 libtoolize --copy --force
413 automake --add-missing --copy --gnu
414 autoconf
415 </pre>
416 <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>
417 </div>
418 <div class="section">
419 <h3><a id="step-2-running-configure" name="step-2-running-configure">Step 2: Running configure</a></h3>
420 <p>In your shell, change directory to the libtorrent directory and run
421 <tt class="docutils literal"><span class="pre">./configure</span></tt>. This will look for libraries and C++ features that libtorrent
422 is dependent on. If something is missing or can't be found it will print an
423 error telling you what failed.</p>
424 <p>The most likely problem you may encounter is that the configure script won't
425 find the boost libraries. Make sure you have boost installed on your system.
426 The easiest way to install boost is usually to use the preferred package
427 system on your platform. Usually libraries and headers are installed in
428 standard directories where the compiler will find them, but sometimes that
429 may not be the case. For example when installing boost on darwin using
430 darwinports (the package system based on BSD ports) all libraries are
431 installed to <tt class="docutils literal"><span class="pre">/opt/local/lib</span></tt> and headers are installed to
432 <tt class="docutils literal"><span class="pre">/opt/local/include</span></tt>. By default the compiler will not look in these
433 directories. You have to set the enviornment variables <tt class="docutils literal"><span class="pre">LDFLAGS</span></tt> and
434 <tt class="docutils literal"><span class="pre">CXXFLAGS</span></tt> in order to make the compiler find those libs. In this example
435 you'd set them like this:</p>
436 <pre class="literal-block">
437 export LDFLAGS=-L/opt/local/lib
438 export CXXFLAGS=-I/opt/local/include
439 </pre>
440 <p>It was observed on FreeBSD (release 6.0) that one needs to add '-lpthread' to
441 LDFLAGS, as Boost::Thread detection will fail without it, even if
442 Boost::Thread is installed.</p>
443 <p>If you need to set these variables, it may be a good idea to add those lines
444 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>
445 <p>If the boost libraries are named with a suffix on your platform, you may use
446 the <tt class="docutils literal"><span class="pre">--with-boost-thread=</span></tt> option to specify the suffix used for the thread
447 library in this case. For more information about these options, run:</p>
448 <pre class="literal-block">
449 ./configure --help
450 </pre>
451 <p>On gentoo the boost libraries that are built with multi-threading support have
452 the suffix <tt class="docutils literal"><span class="pre">mt</span></tt>.</p>
453 <p>You know that the boost libraries were found if you see the following output
454 from the configure script:</p>
455 <pre class="literal-block">
456 checking whether the Boost::DateTime library is available... yes
457 checking for main in -lboost_date_time... yes
458 checking whether the Boost::Filesystem library is available... yes
459 checking for main in -lboost_filesystem... yes
460 checking whether the Boost::Thread library is available... yes
461 checking for main in -lboost_thread... yes
462 </pre>
463 <p>Another possible source of problems may be if the path to your libtorrent
464 directory contains spaces. Make sure you either rename the directories with
465 spaces in their names to remove the spaces or move the libtorrent directory.</p>
466 </div>
467 <div class="section">
468 <h3><a id="creating-a-debug-build" name="creating-a-debug-build">Creating a debug build</a></h3>
469 <p>To tell configure to build a debug version (with debug info, asserts
470 and invariant checks enabled), you have to run the configure script
471 with the following option:</p>
472 <pre class="literal-block">
473 ./configure --enable-debug=yes
474 </pre>
475 </div>
476 <div class="section">
477 <h3><a id="creating-a-release-build" name="creating-a-release-build">Creating a release build</a></h3>
478 <p>To tell the configure to build a release version (without debug info,
479 asserts and invariant checks), you have to run the configure script
480 with the following option:</p>
481 <pre class="literal-block">
482 ./configure --enable-debug=no
483 </pre>
484 <p>The above option make use of -DNDEBUG, which is used throughout libtorrent.</p>
485 </div>
486 <div class="section">
487 <h3><a id="id8" name="id8">Step 3: Building libtorrent</a></h3>
488 <p>Once the configure script is run successfully, you just type <tt class="docutils literal"><span class="pre">make</span></tt> and
489 libtorrent, the examples and the tests will be built.</p>
490 <p>When libtorrent is built it may be a good idea to run the tests, you do this
491 by running <tt class="docutils literal"><span class="pre">make</span> <span class="pre">check</span></tt>.</p>
492 <p>If you want to build a release version (without debug info, asserts and
493 invariant checks), you have to rerun the configure script and rebuild, like this:</p>
494 <pre class="literal-block">
495 ./configure --disable-debug
496 make clean
497 make
498 </pre>
499 </div>
500 </div>
501 <div class="section">
502 <h2><a id="building-with-other-build-systems" name="building-with-other-build-systems">building with other build systems</a></h2>
503 <p>If you're making your own project file, note that there are two versions of
504 the file abstraction. There's one <tt class="docutils literal"><span class="pre">file_win.cpp</span></tt> which relies on windows
505 file API that supports files larger than 2 Gigabytes. This does not work in
506 vc6 for some reason, possibly because it may require windows NT and above.
507 The other file, <tt class="docutils literal"><span class="pre">file.cpp</span></tt> is the default implementation that simply relies
508 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>
509 etc.), this implementation doesn't do anything special to support unicode
510 filenames, so if your target is Windows 2000 and up, you may want to use
511 <tt class="docutils literal"><span class="pre">file_win.cpp</span></tt> which supports unicode filenames.</p>
512 <p>If you're building in MS Visual Studio, you may have to set the compiler
513 options &quot;force conformance in for loop scope&quot;, &quot;treat wchar_t as built-in
514 type&quot; and &quot;Enable Run-Time Type Info&quot; to Yes. For a detailed description
515 on how to build libtorrent with VS, see <a class="reference" href="http://code.rasterbar.com/libtorrent/wiki/Building">the wiki</a>.</p>
516 </div>
517 <div class="section">
518 <h2><a id="build-configurations" name="build-configurations">build configurations</a></h2>
519 <p>By default libtorrent is built In debug mode, and will have pretty expensive
520 invariant checks and asserts built into it. If you want to disable such checks
521 (you want to do that in a release build) you can see the table below for which
522 defines you can use to control the build.</p>
523 <table border="1" class="docutils">
524 <colgroup>
525 <col width="45%" />
526 <col width="55%" />
527 </colgroup>
528 <thead valign="bottom">
529 <tr><th class="head">macro</th>
530 <th class="head">description</th>
531 </tr>
532 </thead>
533 <tbody valign="top">
534 <tr><td><tt class="docutils literal"><span class="pre">NDEBUG</span></tt></td>
535 <td>If you define this macro, all asserts,
536 invariant checks and general debug code will be
537 removed. Since there is quite a lot of code in
538 in header files in libtorrent, it may be
539 important to define the symbol consistently
540 across compilation units, including the clients
541 files. Potential problems is different
542 compilation units having different views of
543 structs and class layouts and sizes.</td>
544 </tr>
545 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_LOGGING</span></tt></td>
546 <td>This macro will enable logging of the session
547 events, such as tracker announces and incoming
548 connections (as well as blocked connections).</td>
549 </tr>
550 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_GEO_IP</span></tt></td>
551 <td>This is defined by default by the Jamfile. It
552 disables the GeoIP features, and avoids linking
553 against LGPL:ed code.</td>
554 </tr>
555 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_VERBOSE_LOGGING</span></tt></td>
556 <td>If you define this macro, every peer connection
557 will log its traffic to a log file as well as
558 the session log.</td>
559 </tr>
560 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_STORAGE_DEBUG</span></tt></td>
561 <td>This will enable extra expensive invariant
562 checks in the storage, including logging of
563 piece sorting.</td>
564 </tr>
565 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_UPNP_LOGGING</span></tt></td>
566 <td>Generates a &quot;upnp.log&quot; file with the UPnP
567 traffic. This is very useful when debugging
568 support for various UPnP routers.
569 support for various UPnP routers.</td>
570 </tr>
571 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISK_STATS</span></tt></td>
572 <td>This will create a log of all disk activity
573 which later can parsed and graphed using
574 <tt class="docutils literal"><span class="pre">parse_disk_log.py</span></tt>.</td>
575 </tr>
576 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_STATS</span></tt></td>
577 <td>This will generate a log with transfer rates,
578 downloading torrents, seeding torrents, peers,
579 connecting peers and disk buffers in use. The
580 log can be parsed and graphed with
581 <tt class="docutils literal"><span class="pre">parse_session_stats.py</span></tt>.</td>
582 </tr>
583 <tr><td><tt class="docutils literal"><span class="pre">UNICODE</span></tt></td>
584 <td>If building on windows this will make sure the
585 UTF-8 strings in pathnames are converted into
586 UTF-16 before they are passed to the file
587 operations.</td>
588 </tr>
589 <tr><td><tt class="docutils literal"><span class="pre">LITTLE_ENDIAN</span></tt></td>
590 <td>This will use the little endian version of the
591 sha-1 code. If defined on a big-endian system
592 the sha-1 hashes will be incorrect and fail.
593 If it is not defined and <tt class="docutils literal"><span class="pre">__BIG_ENDIAN__</span></tt>
594 isn't defined either (it is defined by Apple's
595 GCC) both little-endian and big-endian versions
596 will be built and the correct code will be
597 chosen at run-time.</td>
598 </tr>
599 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_POOL_ALLOCATOR</span></tt></td>
600 <td>Disables use of <tt class="docutils literal"><span class="pre">boost::pool&lt;&gt;</span></tt>.</td>
601 </tr>
602 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_LINKING_SHARED</span></tt></td>
603 <td>If this is defined when including the
604 libtorrent headers, the classes and functions
605 will be tagged with <tt class="docutils literal"><span class="pre">__declspec(dllimport)</span></tt>
606 on msvc and default visibility on GCC 4 and
607 later. Set this in your project if you're
608 linking against libtorrent as a shared library.
609 (This is set by the Jamfile when
610 <tt class="docutils literal"><span class="pre">link=shared</span></tt> is set).</td>
611 </tr>
612 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_BUILDING_SHARED</span></tt></td>
613 <td>If this is defined, the functions and classes
614 in libtorrent are marked with
615 <tt class="docutils literal"><span class="pre">__declspec(dllexport)</span></tt> on msvc, or with
616 default visibility on GCC 4 and later. This
617 should be defined when building libtorrent as
618 a shared library. (This is set by the Jamfile
619 when <tt class="docutils literal"><span class="pre">link=shared</span></tt> is set).</td>
620 </tr>
621 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_DHT</span></tt></td>
622 <td>If this is defined, the support for trackerless
623 torrents will be disabled.</td>
624 </tr>
625 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_DHT_VERBOSE_LOGGING</span></tt></td>
626 <td>This will enable verbose logging of the DHT
627 protocol traffic.</td>
628 </tr>
629 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_ENCRYPTION</span></tt></td>
630 <td>This will disable any encryption support and
631 the openssl dependency that comes with it.
632 Encryption support is the peer connection
633 encrypted supported by clients such as
634 uTorrent, Azureus and KTorrent.</td>
635 </tr>
636 <tr><td><tt class="docutils literal"><span class="pre">_UNICODE</span></tt></td>
637 <td>On windows, this will cause the file IO
638 use wide character API, to properly support
639 non-ansi characters.</td>
640 </tr>
641 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_RESOLVE_COUNTRIES</span></tt></td>
642 <td>Defining this will disable the ability to
643 resolve countries of origin for peer IPs.</td>
644 </tr>
645 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_DISABLE_INVARIANT_CHECKS</span></tt></td>
646 <td>This will disable internal invariant checks in
647 libtorrent. The invariant checks can sometime
648 be quite expensive, they typically don't scale
649 very well. This option can be used to still
650 build in debug mode, with asserts enabled, but
651 make the resulting executable faster.</td>
652 </tr>
653 <tr><td><tt class="docutils literal"><span class="pre">TORRENT_EXPENSIVE_INVARIANT_CHECKS</span></tt></td>
654 <td>This will enable extra expensive invariant
655 checks. Useful for finding particular bugs
656 or for running before releases.</td>
657 </tr>
658 </tbody>
659 </table>
660 <p>If you experience that libtorrent uses unreasonable amounts of cpu, it will
661 definitely help to define <tt class="docutils literal"><span class="pre">NDEBUG</span></tt>, since it will remove the invariant checks
662 within the library.</p>
663 </div>
664 </div>
665 </div>
666 </body>
667 </html>