How-To: Build libtorrent DLL for Windows in C++

September 26th, 2009 127 Commented

-> Last updated: 29 December 2012

To build libtorrent, we need the following components with their respective versions that this guide is using. To keep things simpler, you can omit OpenSSL.

Once we have got the required components downloaded, we can start building steps by steps.

Note: The following sections are for you if you have downloaded the source and not the binaries.

Building Boost Library

I will only cover on how to build boost library by following simple commands. For more details, please read them at Getting started on Windows.

  1. Unzip the boost file to e.g., D:\libtorrent\boost_1_53_0.
  2. Add the environment variable BOOST_ROOT and set its value to the boost folder e.g., D:\libtorrent\boost_1_53_0.
  3. Run the Command Prompt.
  4. Then, run the following commands.
    cd /d %BOOST_ROOT%
    bootstrap
    b2

    The bootstrap command will create b2.exe. Once the bootstrap is completed, we run the b2 command to build the boost source. This will take some time. So, let’s have a cup of coffee while waiting for it.

 

Building OpenSSL Library (Optional)

This section is optional. However, if you wish to include OpenSSL library into your libtorrent, here are the steps to build it.

  1. Download ActivePerl and install it to assist the building of OpenSSL library.
  2. Download NASM and install it if you have not done so.
  3. Add the environment variable OPENSSL and set its value to the openssl folder e.g., D:\libtorrent\openssl-1.0.1c.
  4. Add the environment variable NASM and set its value to the nasm folder e.g., C:\Program Files (x86)\NASM.
  5. Execute the Visual Studio Command Prompt. (It can be found from Start Menu for Windows 7.)
  6. Then, run the following commands.
    perl Configure VC-WIN32 --prefix="%OPENSSL%"
    %NASM%\nasmpath.bat
    call ms\do_nasm
    nmake -f ms\nt.mak

    The OpenSSL libraries are located in folder, out32.

 

Building libtorrent DLL

Assuming that the libtorrent file is unzip to D:\libtorrent\libtorrent-rasterbar-0.16.9.

  1. Add the environment variable LIBTORRENT and set its value to the libtorrent folder e.g., D:\libtorrent\libtorrent-rasterbar-0.16.9.
  2. Create the Win32 Project file (e.g. residing in D:\libtorrent).
  3. You can choose to either create a DLL or static library project. In this post, I will only show you how to create a DLL project. You can also choose to create a static library project if you want to. At the Win32 Application Wizard, choose
    • DLL under application type; and
    • Empty project under Additional options.
  4. Add all the source files in D:\libtorrent\libtorrent-rasterbar-0.16.9\src to your project, including those in its sub-directories. The header files in D:\libtorrent\libtorrent-rasterbar-0.16.9\include\libtorrent can be added too for easy reference.Note: Steps 5 to 7 involves Project->Properties.
    Do not add asio_ssl.cpp if you are NOT including OpenSSL library.
  5. Add the followings to Additional Include Directories under C/C++->General property page.
    $(BOOST_ROOT)
    $(LIBTORRENT)\include
    

    For OpenSSL (optional):
    You will need to include $(OPENSSL)\inc32.

  6. Add the followings to Preprocessor Definitions under C/C++->Preprocessor property page.
    WIN32
    WIN32_LEAN_AND_MEAN
    _WIN32_WINNT=0x0500
    _CRT_SECURE_NO_DEPRECATE
    UNICODE
    BOOST_ASIO_HASH_MAP_BUCKETS=1021
    BOOST_FILESYSTEM_VERSION=2
    WITH_SHIPPED_GEOIP_H
    TORRENT_BUILDING_SHARED
    BOOST_ASIO_SEPARATE_COMPILATION
    BOOST_ASIO_ENABLE_CANCELIO
    TORRENT_USE_TOMMATH
    

    For OpenSSL (optional):
    You need to change TORRENT_USE_TOMMATH to TORRENT_USE_OPENSSL.

  7. Add the followings to Additional Library Directories under Linker->General property page.
    $(BOOST_ROOT)\stage\lib
    

    For OpenSSL (optional):
    You need to include $(OPENSSL)\out32.
    You also need to add libeay32.lib and ssleay32.lib to Additional Dependencies under Linker->General property page.

 

Testing libtorrent DLL

To test the DLL, simply follow the steps below.

  1. Create a Win32 Console Application project file. You need to select the “Empty project” checkbox at the Application Wizard dialog.
  2. Add any cpp file from D:\libtorrent\libtorrent-rasterbar-0.16.6\examples\ to the project
  3. Add the followings to Preprocessor Definitions under C/C++->Preprocessor property page.
    BOOST_FILESYSTEM_VERSION=2
    WITH_SHIPPED_GEOIP_H
    BOOST_ASIO_SEPARATE_COMPILATION
    
  4. Add the file dependencies to Additional Include Directories under C/C++->General property page. You can use the same one from Building libtorrent DLL.
  5. Add the folder where the libtorrent.lib resides into Additional Library Directories under Linker->General property page.
  6. Add libtorrent.lib to Additional Dependencies under Linker->Input property page.
  7. Build the application and voilà! You can test it now with any existing workable torrent.

Note: The examples application may look unpleasant (I don’t own them). Feel free to change the examples code and experience your changes.

Lastly, if you’re having difficulty following the tutorial mentioned above, here are the solutions and project files for both libtorrent and libtorrent with OpenSSL. They are created using Visual C++ 9.0. These files reside in the .\libtorrent folder (refer to the image below).

Note: These project files are created by going through the steps above. You’d need the environment variables for them to compile correctly.

Official libtorrent-rasterbar website http://www.rasterbar.com/products/libtorrent/

Tags:
, , , ,

127 responses to “How-To: Build libtorrent DLL for Windows in C++”

  1. Brad says:

    This is awesome! But I can’t get it working. I’m trying to build libtorrent as a static library, but I keep getting errors (which the debugger cannot catch). The libtorrent website says this:

    If you link statically to the runtime library, you cannot build libtorrent as a shared library (DLL), since you will get separate heaps in the library and in the client application. It will result in crashes and possibly link errors.

    I might be doing it wrong. If you can show me how to make a static version that would be awesome!

    • softz says:

      Hi Brad,
      May I know what are the errors you got? Also, where you using /MT or /MD to do your compilation?

      • liwf says:

        Hi,
        OK,i know it.
        Now,i am studying the libtorrent`s source codes,especially the codes about Local
        service discovery and DHT,are you family with these?
        Before,i thought Local service discovery was designed for one peer to discovery local BitTorrent peers initiativly when it want to download,but now i am doubbing whether i am right.

  2. nitpe says:

    Hello, you could me send the compiled libtorrent.lib and libtorrentd.lib ?
    I had thousands of problems to compile in VC9.0

    my email is:
    power.eptin [a] gmail . com

    thanks

  3. Phil says:

    Hey, for testing the libtorrent library, for steps 4/5 where is the libtorrent.lib located. Did we generate that when making the libtorrent DLL?

    • softz says:

      Hi Phil,

      It should reside in the folder where your libtorrent.dll located. It is created/compiled when you build the libtorrent DLL. My guess, if you didn’t change your project settings, it should be in the debug/release folder of in your solution folder (depending which configuration you build it with).

  4. Joon says:

    Step 6 for building libtorrent DLL. When linking those libraries, I could not locate libeay32.lib or ssleay32.lib, is this a problem?

    • softz says:

      Hi Joon,

      If you have gone through the building of OpenSSL library, you’ll find libeay32.lib and ssleay32.lib in $(OpenSSL)\out32, depending on where you placed your OpenSSL folder (e.g. C:\OpenSSL\out32). Let me know if you have any problem getting that.

      Of course, the compilation of OpenSSL can be removed by specifying a flag in the Preprocessor Definitions. However, I won’t go into it now. If you want to know more, do let me know.

      • Joon says:

        Hi, I have gone through OpenSSL, but I can’t find libeay32lib and ssleay32.lib in $(OpenSSL)\out32. hm… weird.
        oh I just found an error after I ran nmake -f ms\nt.mak

        cl : Command line warning D9035 : option ‘O’ has been deprecated and will be rem
        oved in a future release
        o_str.c
        .\crypto\o_str.c(66) : fatal error C1083: Cannot open include file: ‘strings.h':
        No such file or directory
        NMAKE : fatal error U1077: ‘”C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
        \cl.EXE”‘ : return code ‘0x2′
        Stop.

        Thanks!

        • softz says:

          Hi Joon,

          Did you run “perl Configure VC-WIN32 –prefix=%OpenSSL%” with Visual Studio 2008 Command Prompt under the directory of your OpenSSL folder?

          Example (for my test case here):
          D:\openssl-1.0.0a>perl Configure VC-WIN32 –prefix=%OpenSSL%

          Your results will be something like the following:

          
          Configuring for VC-WIN32
              no-gmp          [default]  OPENSSL_NO_GMP (skip dir)
              no-jpake        [experimental] OPENSSL_NO_JPAKE (skip dir)
              no-krb5         [krb5-flavor not specified] OPENSSL_NO_KRB5
              no-md2          [default]  OPENSSL_NO_MD2 (skip dir)
              no-rc5          [default]  OPENSSL_NO_RC5 (skip dir)
              no-rfc3779      [default]  OPENSSL_NO_RFC3779 (skip dir)
              no-shared       [default]
              no-store        [experimental] OPENSSL_NO_STORE (skip dir)
              no-zlib         [default]
              no-zlib-dynamic [default]
          IsMK1MF=1
          CC            =cl
          CFLAG         =-DOPENSSL_THREADS  -DDSO_WIN32 -W3 -WX -Gs0 -GF -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN ... < more of the definitions here >
          EX_LIBS       =
          CPUID_OBJ     =x86cpuid.o
          BN_ASM        =bn-586.o co-586.o x86-mont.o
          DES_ENC       =des-586.o crypt586.o
          AES_ENC       =aes-586.o
          BF_ENC        =bf-586.o
          CAST_ENC      =cast-586.o
          RC4_ENC       =rc4-586.o
          RC5_ENC       =rc5-586.o
          MD5_OBJ_ASM   =md5-586.o
          SHA1_OBJ_ASM  =sha1-586.o sha256-586.o sha512-586.o
          RMD160_OBJ_ASM=rmd-586.o
          CMLL_ENC=     =cmll-x86.o
          PROCESSOR     =
          RANLIB        =true
          ARFLAGS       =
          PERL          =perl
          THIRTY_TWO_BIT mode
          BN_LLONG mode
          RC4_INDEX mode
          RC4_CHUNK is undefined
          
          Configured for VC-WIN32.

          If you look at the CFLAG values, you will find -DOPENSSL_SYSNAME_WIN32, this actually disable the #include in the o_str.c

          If look into the file o_str.c, you’ll see:

          
          #if !defined(OPENSSL_IMPLEMENTS_strncasecmp) && \
              !defined(OPENSSL_SYSNAME_WIN32) && \
              !defined(NETWARE_CLIB)
          # include 
          #endif

          So two checks here. First make sure you are running the command under Visual Studio Command Prompt and the CFLAG has the mentioned flag.

          Also, you can open up the Configure file in the OpenSSL folder. Do a find on “OPENSSL_SYSNAME_WIN32″, you will see it in VC-WIN32 target. You can add it there or re-download the OpenSSL if it’s not there.

          Hope it helps.

  5. Luna-Tic says:

    I have this error to, my solution was perl Configure VC-WIN32 -–prefix=”dir” like linux\bsd — not – (one)

  6. LoopBack says:

    Can you give me the libtorrent.lib and other libs that can use under the windows?

    e-mail:dll8874@gmail.com
    thank you

    • softz says:

      Hi, I just sent your the libtorrent.lib. Sorry for the delay. I was in overseas. If I remember correctly, it’s a DLL. So, all libraries should be in the DLL. Hope it helps.

  7. cb says:

    Thanks. I built the DLL using VC 2010.

  8. KMVS says:

    Hi,

    I’m very new to libtorrent and I am trying to build libtorrent 0_15_5 using

    boost_1_46_1
    msvc 2010 express

    All though, I could build dll. When I try to test using examples, the test program throws errors

    for example, If I try to test make_torrent.

    I get the following errors
    1> make_torrent.cpp
    1>d:\libtorrent\include\libtorrent\file_storage.hpp(110): error C2572: ‘libtorrent::file_storage::add_file’ : redefinition of default parameter : parameter 5
    1> d:\libtorrent\include\libtorrent\file_storage.hpp(106) : see declaration of ‘libtorrent::file_storage::add_file’
    1>d:\libtorrent\include\libtorrent\file_storage.hpp(110): error C2572: ‘libtorrent::file_storage::add_file’ : redefinition of default parameter : parameter 4
    1> d:\libtorrent\include\libtorrent\file_storage.hpp(106) : see declaration of ‘libtorrent::file_storage::add_file’
    1>d:\libtorrent\include\libtorrent\file_storage.hpp(110): error C2572: ‘libtorrent::file_storage::add_file’ : redefinition of default parameter : parameter 3
    1> d:\libtorrent\include\libtorrent\file_storage.hpp(106) : see declaration of ‘libtorrent::file_storage::add_file’
    1>d:\libtorrent\include\libtorrent\file_storage.hpp(110): error C2535: ‘void libtorrent::file_storage::add_file(const boost::filesystem3::path &,libtorrent::size_type,int,time_t,const boost::filesystem3::path &)’ : member function already defined or declared
    1> d:\libtorrent\include\libtorrent\file_storage.hpp(106) : see declaration of ‘libtorrent::file_storage::add_file’
    1>d:\libtorrent\include\libtorrent\file_storage.hpp(110): error C2548: ‘libtorrent::file_storage::add_file’ : missing default parameter for parameter 3
    1>d:\libtorrent\include\libtorrent\file_storage.hpp(110): error C2548: ‘libtorrent::file_storage::add_file’ : missing default parameter for parameter 4
    1>d:\libtorrent\include\libtorrent\file_storage.hpp(110): error C2548: ‘libtorrent::file_storage::add_file’ : missing default parameter for parameter 5
    1>d:\libtorrent\include\libtorrent\file_storage.hpp(173): fatal error C1903: unable to recover from previous error(s); stopping compilation
    Please let me know, If I am doing any mistake.

    Cheers,
    KMVS

  9. Geomma says:

    you could me send the Visual Studio Project Files?
    I had many problems to compile in VC10.0

  10. Geomma says:

    hi
    i get the following errors.

    ——————-

    > nmake -f ms/nt.mak

    Building OpenSSL
    cl /Fotmp32\cryptlib.obj -Iinc32 -Itmp32 /MT /Ox /O2 /Ob2 -DOPENSSL_THREADS -DDSO_WIN32 -W3 -Gs0 -GF -Gy -nolo
    go -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -D_CRT_SECURE_NO_DEPRECATE -DOPENSSL_BN_ASM_PART_WORDS -DOPE
    NSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DWHIRLPOOL_A
    SM -DOPENSSL_NO_RC5 -DOPENSSL_NO_MD2 -DOPENSSL_NO_KRB5 -DOPENSSL_NO_JPAKE -DOPENSSL_NO_DYNAMIC_ENGINE /Zl /Zi /Fdtmp32/l
    ib -c .\crypto\cryptlib.c
    NMAKE : fatal error U1077: ‘.\cl.EXE’ : return code ‘0xc0000135′
    Stop.

    —————

    please help me…

  11. WalkMan says:

    Hi! Do you know how to build it all for python? I read all manuals on official libtorrent site, but i have some problems with one of this part.

  12. Tim Trahan says:

    Not to be a me also, but I have tried compiling this library and have been unable to do so. I am writing an app that will use a bittorrent engine to download files. I am using visual studio 2010. Can you send me the compiled dll’s to ttrahan@comcast.net? I have gotten monotorrent to work, but it seems quite buggy. Is there a place to go to get the pre-compiled dlls for this or does everybody just figure out how to build there own?

    Thanks!
    Tim

    • softz says:

      The last time I didn’t notice any pre-compiled dlls. I don’t know about it now. But, I’ll send you the compiled files and the project files (you need the .h file for your applications).

  13. M. Bedda says:

    Hello,

    I’ve had a trouble going smoothly through the above steps, can you send me the dll’s on mbedda@techberg.com. Thanks.

    • M. Bedda says:

      Managed to save at the end thanks man for your tutorial, it was really helpful.

      • M. Bedda says:

        I mean managed to build

      • softz says:

        I’m glad to hear that you managed to build it. Sorry I was busy and didn’t notice your comments. Let me know if you’d still need anything. :)

        • M. Bedda says:

          Did u try building the client_test example? I’m getting lots of errors like this one:

          Error 119 error LNK2019: unresolved external symbol “bool __cdecl libtorrent::from_hex(char const *,int,char *)” (?from_hex@libtorrent@@YA_NPBDHPAD@Z) referenced in function _main C:\libtorrent\client_test\client_test\client_test.obj client_test

          I’m trying to use this library within a c# application, did you try something like that out? I didn’t use c++ libraries in c#, do you think I would be able to work that out at the end?

          • softz says:

            Hi,

            Yep, I tried the client_test example and it worked fine. For that error, you might want to check if your libtorrent.lib is included into the test project. The compiler is complaining that it couldn’t find the code for the function from_hex(char const *,int,char *)

            To support C# application, you might need to do quite a bit of marshaling work since it’s not a COM object. However, you can always try MonoTorrent as an alternative, it is written in C# and I guess it’d serve your purpose well.

  14. ryandaniels says:

    Hey, sorry if I’m being dense, but there seems to be step you left out;

    I couldn’t find the C/C++ section in the properties page, so I searched around, and I just discovered that this section does not show up until you have at least one .cpp file.

    SO my question is: after I make a project in libtorrent/win32, how exactly am I supposed to get all the headers and .cpp files to show up in my project folders (presumably so they can actually compile)? I could try to do it manually, but then I lose directory structure… Basically, if I follow your steps exactly, I just end up with a empty project.

    Other than this hiccup this tutorial has been great, so thanks!

    • ryandaniels says:

      Well, after retrying with a blank foo.cpp file, it worked.

    • softz says:

      Hi,

      I’m glad you found the solutions. Yep, you need to have at least one cpp file in order for you to access the C/C++ section properties. Probably, I should state that in the steps too. Sorry about that and I hope the library serves you well.

      • ryandaniels says:

        Thanks for the quick reply; however I now have a new problem. I was able to compile a dll and lib file, but I’m not sure they contain any actual useful information.

        I attempted to compile one of the sample programs, and I eventually ran into the expected linker error referencing a bunch of libtorrent stuff. So, I went ahead and added libtorrent.lib to my additional dependencies (and added the library folder), and to my surprise, none of the linker errors went away.

        I noticed that when compiling libtorrent, it goes quite quickly, and it turns out I can remove pretty much any seemingly vital settings (such as all the additional dependencies) and it still compiles fine. So obviously nothing is actually going into my lib or dll files when I compile libtorrent.

        I tried also adding the libtorrent/src folder to the “Source Directories” list, no effect. I think I’m missing something important here, so I’m sorry for what will probably be an embarrassingly simple and obvious mistake.

        • softz says:

          If you are trying to compile the test source code provided by libtorrent, do take note that they are using lots of boost. So, you may need to include the respective headers and libraries of boost if you haven’t done so. It’ll help if you could let me know what are the exact errors.

  15. Hesham says:

    Hello,

    Could you please send me the compiled DLL by mail???

    Thanks in advance!

  16. George says:

    Anybody knows how do I make a DLL that works in C#?

  17. autojack says:

    Pls i need project files in vs2005 or 08

  18. Francesco says:

    Hi,

    I’m very new to libtorrent and I am trying to build libtorrent 0_15_5 using Boost library 1.40 and libtorrent library 0.15.8

    During the building boost library,at the step 4 i get the following errors:

    Building Boost.Jam build engine
    Can not find the file specified.
    “cl” is not recognized as internal or external command,
    an executable program or batch file.

    Failed to build Boost.Jam build engine.
    Please consult bjam.log for furter diagnostics.

    You can try to obtain a prebuilt binary from

    http://sf.net/project/showfiles.php?group_id=7586&package_id=72941

    Also, you can file an issue at http://svn.boost.org
    Please attach bjam.log in that case.

    please help me..

  19. thienlong says:

    I built libtorrent dll and simple_client in libtorrent/samples. But i got error when run it: “The program can’t start because torrent.dll is missing from your computer. Try reinstalling the program to fix this problem”
    Please help me..

    • softz says:

      Hi, is your working directory set to the appropriate folder? For simplicity, the dll and exe should be in the same folder. So, if your files resides in C:\torrent, then when you run your command prompt, the directory should be set to C:\torrent. Of course, you can also set the PATH. But, the previous one is simpler.

  20. tim says:

    hi, i tried to build libtorrent, i created an empty .cpp (in order to show to me c++ properties). Then i build the project, i went into project folder but i couldn’t find libtorrent.lib,
    what i am doing wrong? how create libtorrent.lib?
    Thanks..

    • softz says:

      Hi Tim, my bad… I realized that I’ve missed out a step. Just updated it. You need not create an empty .cpp, you’d need to add the libtorrent source files to your project and set the properties. You can refer to the updated steps. Thanks for alerting.

      • tim says:

        ok ,thanks for answer. It works but i have now another problem. I build my project with VS2008 and it starts compile the files but finally it show me an error
        (c:\libtorrent\libtorrent-rasterbar-0.15.8\src\ut_pex.cpp : error C2471: cannot update program database ‘c:\libtorrent\build\obj\debug\libtorrent\vc90.pdb’
        c:\libtorrent\libtorrent-rasterbar-0.15.8\src\ut_pex.cpp : fatal error C1083: Cannot open program database file: ‘c:\libtorrent\build\obj\debug\libtorrent\vc90.pdb': No such file or directory),
        i went into debug\libtorrent folder and i saw that vc90.pdb exists. What is going wrong?

        • softz says:

          Try “Clean Solution” to delete all the object files.
          If problem still persists, you can try closing VS and delete the build folder manually.

          • tim says:

            Thanks for answer, is there any other way to use libtorrent? If you send me .lib and .dll file it will works?

          • softz says:

            You can refer to the client code to understand how to use libtorrent. You can also run the simple_client.exe with a torrent file as an argument and see the torrent library in action.

            You can download my solution and project files listed above. It will build the library and sample clients showing how the libtorrent is used. It’s a VS2008 solution and it pretty straight forward.

            Do let me know if you encounter any issues.

          • tim says:

            I tried to compline your solution, it runs forn about 2 minutes but then tells build failed.. :-(

            c:\libtorrent\libtorrent-rasterbar-0.15.8\include\libtorrent\entry.hpp(81): warning C4275: non dll-interface class ‘std::runtime_error’ used as base for dll-interface struct ‘libtorrent::type_error’
            1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdexcept(158) : see declaration of ‘std::runtime_error’
            1> c:\libtorrent\libtorrent-rasterbar-0.15.8\include\libtorrent\entry.hpp(80) : see declaration of ‘libtorrent::type_error’
            1>c:\libtorrent\boost_1_49_0\boost\exception\detail\exception_ptr.hpp(17): fatal error C1189: #error : This header requires exception handling to be enabled.
            1> Generating Code…
            1>
            1>Build FAILED.
            1>
            1>Time Elapsed 00:02:00.64
            ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

          • softz says:

            I see… You’re getting this error because you’re using boost_1_49_0 instead of the one I listed boost_1_40_0.

            Ok, if you want to use boost_1_49_0, you need to remove BOOST_NO_EXCEPTIONS from the Preprocessor Definition.

            Also, you need to add BOOST_FILESYSTEM_VERSION=2 to the Preprocessor Definition in all the sample client projects in the solution.

            These should solve your issues. Also, all the projects use UNICODE.

            I’ll try to update this page to use the latest Boost when time permits. :D

          • tim says:

            Thanks, it works finally.
            I also build the simple_client project.. but when i try to run it, it
            says :
            ‘simple_client.exe': Loaded ‘C:\libtorrent\Build\bin\Debug\simple_client.exe’, Symbols loaded.
            ‘simple_client.exe': Loaded ‘C:\Windows\SysWOW64\ntdll.dll’, Symbols loaded (source information stripped).
            ‘simple_client.exe': Loaded ‘C:\Windows\SysWOW64\kernel32.dll’, Symbols loaded (source information stripped).
            ‘simple_client.exe': Loaded ‘C:\Windows\SysWOW64\KernelBase.dll’, Symbols loaded (source information stripped).
            ‘simple_client.exe': Loaded ‘C:\libtorrent\Build\bin\Debug\libtorrent.dll’, Symbols loaded.
            ‘simple_client.exe': Loaded ‘C:\Windows\SysWOW64\ws2_32.dll’, Symbols loaded (source information stripped).
            The program ‘[4124] simple_client.exe: Native’ has exited with code 1 (0x1).

          • tim says:

            I find it, sorry. I run it from cmd and it works..
            Thanks for the support :-)

          • softz says:

            Great to know you’ve got it running :D

  21. John Coss says:

    Hi. I am also trying to build libtorrent library. I followed your steps (install boost 1_49_0, download and import libtorrent-rasterbar 0.15.8) and created project in VS2008. However when I try to build libtorrent.lib (as DLL) I have linker errors (compile has only bunch of warrnings):
    Linking…
    Creating library f:\libtorrent\torrentbuild\Release\torrentbuild.lib and object f:\libtorrent\torrentbuild\Release\torrentbuild.exp
    gzip.obj : error LNK2001: unresolved external symbol _inflateInit2_
    gzip.obj : error LNK2001: unresolved external symbol _inflate
    gzip.obj : error LNK2001: unresolved external symbol _inflateEnd
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::on_unreachable(class boost::asio::ip::basic_endpoint const &)” (?on_unreachable@dht_tracker@dht@libtorrent@@QAEXABV?$basic_endpoint@Vudp@ip@asio@boost@@@ip@asio@boost@@@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::on_receive(class boost::asio::ip::basic_endpoint const &,char const *,int)” (?on_receive@dht_tracker@dht@libtorrent@@QAEXABV?$basic_endpoint@Vudp@ip@asio@boost@@@ip@asio@boost@@PBDH@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::network_stats(int &,int &)” (?network_stats@dht_tracker@dht@libtorrent@@QAEXAAH0@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::dht_status(struct libtorrent::session_status &)” (?dht_status@dht_tracker@dht@libtorrent@@QAEXAAUsession_status@3@@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “public: class libtorrent::entry __thiscall libtorrent::dht::dht_tracker::state(void)const ” (?state@dht_tracker@dht@libtorrent@@QBE?AVentry@3@XZ)
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::add_router_node(class boost::asio::ip::basic_endpoint const &)” (?add_router_node@dht_tracker@dht@libtorrent@@QAEXABV?$basic_endpoint@Vudp@ip@asio@boost@@@ip@asio@boost@@@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::add_node(class boost::asio::ip::basic_endpoint)” (?add_node@dht_tracker@dht@libtorrent@@QAEXV?$basic_endpoint@Vudp@ip@asio@boost@@@ip@asio@boost@@@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::add_node(struct std::pair,class std::allocator >,int> const &)” (?add_node@dht_tracker@dht@libtorrent@@QAEXABU?$pair@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@std@@@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::stop(void)” (?stop@dht_tracker@dht@libtorrent@@QAEXXZ)
    session_impl.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::start(class libtorrent::entry const &)” (?start@dht_tracker@dht@libtorrent@@QAEXABVentry@3@@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “public: __thiscall libtorrent::dht::dht_tracker::dht_tracker(struct libtorrent::aux::session_impl &,struct libtorrent::rate_limited_udp_socket &,struct libtorrent::dht_settings const &,class libtorrent::entry const *)” (??0dht_tracker@dht@libtorrent@@QAE@AAUsession_impl@aux@2@AAUrate_limited_udp_socket@2@ABUdht_settings@2@PBVentry@2@@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “void __cdecl libtorrent::dht::intrusive_ptr_release(struct libtorrent::dht::dht_tracker const *)” (?intrusive_ptr_release@dht@libtorrent@@YAXPBUdht_tracker@12@@Z)
    session_impl.obj : error LNK2001: unresolved external symbol “void __cdecl libtorrent::dht::intrusive_ptr_add_ref(struct libtorrent::dht::dht_tracker const *)” (?intrusive_ptr_add_ref@dht@libtorrent@@YAXPBUdht_tracker@12@@Z)
    smart_ban.obj : error LNK2001: unresolved external symbol _adler32
    torrent.obj : error LNK2001: unresolved external symbol “public: void __thiscall libtorrent::dht::dht_tracker::announce(class libtorrent::big_number const &,int,class boost::function,class std::allocator > > const &)>)” (?announce@dht_tracker@dht@libtorrent@@QAEXABVbig_number@3@HV?$function@$$A6AXABV?$vector@V?$basic_endpoint@Vtcp@ip@asio@boost@@@ip@asio@boost@@V?$allocator@V?$basic_endpoint@Vtcp@ip@asio@boost@@@ip@asio@boost@@@std@@@std@@@Z@boost@@@Z)
    f:\libtorrent\torrentbuild\Release\torrentbuild.dll : fatal error LNK1120: 18 unresolved externals

    Any ideas how to solve this?
    Thanks in advance!

    • softz says:

      Hi, it looks like you have not added the .c or .cpp from zlib and kademlia for compilation. After adding them, you should have no problem compiling. You can also download the solution and project files for your reference. Hope it helps.

      • John Coss says:

        Hi,
        Thank you for your answer. I was able to build libtorrent.lib now.
        I had problems to build examples, but I managed to do that somehow.
        In Project Properties go to C/C++ Preprocesor and add all these lines:
        WIN32
        NDEBUG
        _CONSOLE
        BOOST_FILESYSTEM_VERSION=2

        If you omit first three lines, you get compile error as could not be found (I think that defining of WIN32 fixed this error)
        Additional include directories in C/C++ general remains the same:
        $(BOOST_ROOT)
        $(LIBTORRENT)\include
        $(LIBTORRENT)\zlib

        In Linker/general under Additional Library Directories you need to insert:
        $(BOOST_ROOT)\stage\lib
        $(OutDir)

        Last line can also be absolute path to your compiled libtorrent.lib.
        Linker/Input under Additional Dependencies remains also the same:
        libtorrent.lib
        or the name of project that builds the libtorrent sources

        Most of these information I found in attached solutions and project files. They really help a lot!!

        However, I have problem with simple_client example. It is build correctly (I guess), but I can’t download anything. I used torrent file with lots of seeders but it won’t begin download (it asked me to add it as exception to windows firewall and I answered positive). uTorrent client have no problem with it. Any ideas what am I missing here?

        Again thanks for information about building libtorrent.lib :D

        • softz says:

          Hi John,

          Yep, you need to set the preprocessor and include the library directories for the sample too. The sample is using boost too, so boost library information is needed too.

          As for the simple_client.exe, it works on my side except that it doesn’t print anything on the console. If you want to view the information, you might want to try with client_test.exe instead. However, the formatting isn’t very nice, you can format it nicely in the client_test.cpp code.

          Just a note, do make sure also your antivirus is not blocking the application or is not running it in a sandbox. My antivirus tries to run all my self-programmed applications in a sandbox.

          In fact, the download speed is very impressive too. Hope it helps. :D

  22. IMOPTRA says:

    hi softz,
    very good article. but i am not able to make it work. please send the libtorrent.dll or libtorrent.lib to my mail id…

    Thanks in advance

  23. fox4305 says:

    Hi :)

    Can you send me the dll and lib file please ? have a good day and thanks :)

  24. Virt says:

    Can you help? I’ve compiled OpenSSL with do_ms.bat, and I get a whole mess of errors:

    I am using LibTorrent 16.6, Boost 1.52, and OpenSSL 1.0.1c. Most odd-looking are the missing conf.h and the out of heap space.

    1 IntelliSense: identifier “SSL_VERIFY_NONE” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\verify_mode.hpp 53 25 libtorrent166
    2 IntelliSense: identifier “SSL_VERIFY_PEER” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\verify_mode.hpp 54 25 libtorrent166
    3 IntelliSense: identifier “SSL_VERIFY_FAIL_IF_NO_PEER_CERT” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\verify_mode.hpp 55 41 libtorrent166
    4 IntelliSense: identifier “SSL_VERIFY_CLIENT_ONCE” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\verify_mode.hpp 56 32 libtorrent166
    5 IntelliSense: identifier “SSL_CTX” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\context.hpp 53 11 libtorrent166
    6 IntelliSense: identifier “SSL_CTX” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\context.hpp 56 11 libtorrent166
    7 IntelliSense: identifier “X509_STORE_CTX” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\context.hpp 503 24 libtorrent166
    8 IntelliSense: identifier “X509_STORE_CTX” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\impl\context.ipp 452 56 libtorrent166
    9 IntelliSense: identifier “SSL_CTX” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\engine.hpp 64 35 libtorrent166
    10 IntelliSense: identifier “SSL” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\engine.hpp 70 19 libtorrent166
    11 IntelliSense: identifier “X509_STORE_CTX” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\engine.hpp 117 24 libtorrent166
    12 IntelliSense: identifier “SSL” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\engine.hpp 145 3 libtorrent166
    13 IntelliSense: identifier “BIO” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\engine.hpp 146 3 libtorrent166
    14 IntelliSense: identifier “SSL_CTX” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\impl\engine.ipp 37 16 libtorrent166
    15 IntelliSense: identifier “SSL” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\impl\engine.ipp 72 1 libtorrent166
    16 IntelliSense: identifier “X509_STORE_CTX” is undefined c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\impl\engine.ipp 101 55 libtorrent166
    17 IntelliSense: cannot open source file “openssl/conf.h” c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\openssl_types.hpp 19 1 libtorrent166
    18 IntelliSense: cannot open source file “openssl/ssl.h” c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\openssl_types.hpp 20 1 libtorrent166
    19 IntelliSense: cannot open source file “openssl/engine.h” c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\openssl_types.hpp 22 1 libtorrent166
    20 IntelliSense: cannot open source file “openssl/err.h” c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\openssl_types.hpp 24 1 libtorrent166
    21 IntelliSense: cannot open source file “openssl/x509v3.h” c:\ActiveWorking\boost_1_52_0\boost\asio\ssl\detail\openssl_types.hpp 25 1 libtorrent166
    Error 97 error C1060: compiler is out of heap space c:\activeworking\libtorrent\libtorrent-rasterbar-0.16.6\src\udp_socket.cpp 535 1 libtorrent166

  25. Virt says:

    Heap space fixed (odd fluke, apparently) all the intellisense and the conf.h still broken.

  26. Virt says:

    Ok, got both of those fixed (#@$!#@ VS) and now am hung up on this one:

    Error 622 error LNK2019: unresolved external symbol _sk_num referenced in function “public: bool __thiscall boost::asio::ssl::rfc2818_verification::operator()(bool,class boost::asio::ssl::verify_context &)const ” (??Rrfc2818_verification@ssl@asio@boost@@QBE_N_NAAVverify_context@123@@Z) C:\ActiveWorking\libtorrent\libtorrent166\libtorrent166\asio_ssl.obj libtorrent166
    Error 623 error LNK2019: unresolved external symbol _sk_value referenced in function “public: bool __thiscall boost::asio::ssl::rfc2818_verification::operator()(bool,class boost::asio::ssl::verify_context &)const ” (??Rrfc2818_verification@ssl@asio@boost@@QBE_N_NAAVverify_context@123@@Z) C:\ActiveWorking\libtorrent\libtorrent166\libtorrent166\asio_ssl.obj libtorrent166
    Error 624 error LNK2019: unresolved external symbol _CRYPTO_cleanup_all_ex_data referenced in function “public: __thiscall boost::asio::ssl::detail::openssl_init_base::do_init::~do_init(void)” (??1do_init@openssl_init_base@detail@ssl@asio@boost@@QAE@XZ) C:\ActiveWorking\libtorrent\libtorrent166\libtorrent166\asio_ssl.obj libtorrent166
    Error 625 error LNK2019: unresolved external symbol _CRYPTO_num_locks referenced in function “public: __thiscall boost::asio::ssl::detail::openssl_init_base::do_init::do_init(void)” (??0do_init@openssl_init_base@detail@ssl@asio@boost@@QAE@XZ) C:\ActiveWorking\libtorrent\libtorrent166\libtorrent166\asio_ssl.obj libtorrent166
    ……etc.

    • softz says:

      Hi, make sure you added the needed library for ssl since you are using ssl.

      • Virt says:

        I might be missing something; which lib is that? I’ve added the whole directory of boost and openSSL and libtorrent as additional include entries.

        • softz says:

          From the error, it looks like you are having some issues with asio_ssl source(cpp) that comes with libtorrent.

          Edited: I’ve updated the post. Try following or downloading the project files to see what you are missing.

  27. mitja.gti says:

    Hi!

    I’m trying to build libtorrent version 0.16.9 with boost 1.53.0 and Visual Studio 2012. Getting all sort of problems. Is there any chance you will update your post with instructions for building using latest versions any time soon?

    Thank you.

  28. mitja.gti says:

    I’m afraid that it does not. I’m almost half way there… need to go trough the source code and repair it, because it doesn’t compile.
    If I manage to get it working I’ll let you know.

    Thanks for the reply.

    • softz says:

      Hi,

      I’ve updated to the new boost (v1.53.0) and libtorrent (v0.16.9). I just built boost and updated the libtorrent source files location using the same project settings in the file I provided from this page and every thing works fine.

      If you can’t get them to work, you can download the libtorrent.7z file which contains the solution and project files.

      Cheers :)

    • softz says:

      Make sure you have all the correct Preprocessor definitions, and Include and Libraries directories specified.

      • mitja.gti says:

        Great news, I finally got it working.
        Following your tutorial really helped me out, but as I have said, there are also some errors in the source code. I went trough it and modified all of them (like assigning a negative int to unsigned int, etc).

        Thanks for the post and all the help.

        • softz says:

          Great that you’ve got it working. :)

          I’ve tried it out with VS2012. It built successfully with the provided solution without any code change. I prefer treating the open source as a black box and not changing to keep future updates simple and less hassle.

          For your case, did you set your project settings to treat warning as errors? As far as I know, there are lots of warnings in the compilation.

  29. tartane says:

    Where did you upload the libtorrent.7z file?

  30. tartane says:

    nvm i found the libtorrent.7z haha :P i’m having trouble compiling it, can you send the built dll to me?

  31. Sergey says:

    Hi.

    Have problem with libtorrent. Use algorithm from this site with one exception – i build static library. Use MSVC-10.0 and boostpro (but this is irrelevant – latest boost generate same result).

    Library compiled, test project simple_client compiled. I cannot download anything from my computer because corporation politic (protocol blocked). When i run simple_client or client_test, i receive exception – heap corrupted. Exception fired when i try destruct session, that have worked torrents (its all paused). All look like boost threads free memory, that next time try to free main thread.

    • softz says:

      Hi,

      Thank you for the feedback. I’ve not encountered any of those before, maybe I can try manually blocking the port at home. However, I aware that the test application does contain some crash issue, the library is fine though.

      As I don’t own the code, you might want to check out the official website for more information.

  32. gkub says:

    HI, I follow your tutorial, and I use vs2003, but when compile it give me this error:

    libtorrent-rasterbar-0.16.9\src\session.cpp(585) : error C2947 expecting ‘>’ to terminate template-argument list, but found ‘>>’
    libtorrent-rasterbar-0.16.9\src\file.cpp(1460) : error C2065: “ERROR_CANT_WAIT” : not declare name

    any idea what is wrong?

    • softz says:

      Hi, sorry for the late reply. I’ve roughly looked thru’ the code. There shouldn’t be any error. For line no. 585, can you check and make sure “>>” are not joined together. It will be interpreted as a shift-right by the compiler. For line no. 1460, ERROR_CANT_WAIT is defined in WinError.h. Can you double check if your Preprocessor Definitions are set correctly? And the libtorrent source code has not been altered at all.

  33. mike says:

    Please send me the binary (lib/dll) as well! mike@easystyle.org… thanks

  34. ragu says:

    Hi,

    i am trying to compile libtorrent for windows i am getting redefinition errors how to solve this.Following are errors.

    Error 973 error LNK2019: unresolved external symbol __imp___wstat64 referenced in function “void __cdecl libtorrent::stat_file(class std::basic_string<char,struct std::char_traits,class std::allocator >,struct libtorrent::file_status *,class boost::system::error_code &,int)” (?stat_file@libtorrent@@YAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PAUfile_status@1@AAVerror_code@system@boost@@H@Z) libtorrent.lib
    Error 974 error LNK2019: unresolved external symbol __imp___wrename referenced in function “void __cdecl libtorrent::rename(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class boost::system::error_code &)” (?rename@libtorrent@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0AAVerror_code@system@boost@@@Z) libtorrent.lib
    Error 975 error LNK2019: unresolved external symbol __imp___wgetcwd referenced in function “class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl libtorrent::current_working_directory(void)” (?current_working_directory@libtorrent@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) libtorrent.lib
    Error 979 error LNK2019: unresolved external symbol __imp___invalid_parameter_noinfo referenced in function “public: class boost::intrusive_ptr const & __thiscall std::_Vector_const_iterator<class boost::intrusive_ptr,class std::allocator<class boost::intrusive_ptr > >::operator*(void)const ” (??D?$_Vector_const_iterator@V?$intrusive_ptr@Vbasic_cv_list_entry@detail@boost@@@boost@@V?$allocator@V?$intrusive_ptr@Vbasic_cv_list_entry@detail@boost@@@boost@@@std@@@std@@QBEABV?$intrusive_ptr@Vbasic_cv_list_entry@detail@boost@@@boost@@XZ) libboost_thread-vc90-mt-sgd-1_53.lib
    Error 977 error LNK2019: unresolved external symbol __imp___fstat64i32 referenced in function _fstat libtorrent.lib
    Error 972 error LNK2019: unresolved external symbol “__declspec(dllimport) void (__cdecl*__cdecl _set_se_translator(void (__cdecl*)(unsigned int,struct _EXCEPTION_POINTERS *)))(unsigned int,struct _EXCEPTION_POINTERS *)” (__imp_?_set_se_translator@@YAP6AXIPAU_EXCEPTION_POINTERS@@@ZP6AXI0@Z@Z) referenced in function “public: __thiscall libtorrent::aux::eh_initializer::eh_initializer(void)” (??0eh_initializer@aux@libtorrent@@QAE@XZ) libtorrent.lib
    Error 107 error LNK2005: “void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)” (?_Debug_message@std@@YAXPB_W0I@Z) already defined in libcpmtd.lib(stdthrow.obj) msvcprtd.lib
    Error 140 error LNK2005: “public: wchar_t const * __thiscall std::basic_string<wchar_t,struct std::char_traits,class std::allocator >::c_str(void)const ” (?c_str@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEPB_WXZ) already defined in common.obj msvcprtd.lib
    Error 130 error LNK2005: “public: void __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::swap(class std::basic_string<char,struct std::char_traits,class std::allocator > &)” (?swap@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEXAAV12@@Z) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 128 error LNK2005: “public: void __thiscall std::allocator::deallocate(char *,unsigned int)” (?deallocate@?$allocator@D@std@@QAEXPADI@Z) already defined in common.obj msvcprtd.lib
    Error 123 error LNK2005: “public: void __thiscall std::_Container_base_secure::_Swap_aux(class std::_Container_base_secure &)” (?_Swap_aux@_Container_base_secure@std@@QAEXAAV12@@Z) already defined in common.obj msvcprtd.lib
    Error 124 error LNK2005: “public: void __thiscall std::_Container_base_secure::_Swap_all(class std::_Container_base_secure &)const ” (?_Swap_all@_Container_base_secure@std@@QBEXAAV12@@Z) already defined in common.obj msvcprtd.lib
    Error 110 error LNK2005: “public: void __thiscall std::_Container_base_secure::_Orphan_all(void)const ” (?_Orphan_all@_Container_base_secure@std@@QBEXXZ) already defined in common.obj msvcprtd.lib
    Error 139 error LNK2005: “public: unsigned int __thiscall std::basic_string<wchar_t,struct std::char_traits,class std::allocator >::size(void)const ” (?size@?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QBEIXZ) already defined in common.obj msvcprtd.lib
    Error 100 error LNK2005: “public: unsigned int __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::size(void)const ” (?size@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in common.obj msvcprtd.lib
    Error 131 error LNK2005: “public: unsigned int __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::length(void)const ” (?length@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 141 error LNK2005: “public: unsigned int __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::find_last_of(char,unsigned int)const ” (?find_last_of@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIDI@Z) already defined in curl_wrapper.obj msvcprtd.lib
    Error 129 error LNK2005: “public: unsigned int __thiscall std::allocator::max_size(void)const ” (?max_size@?$allocator@D@std@@QBEIXZ) already defined in common.obj msvcprtd.lib
    Error 115 error LNK2005: “public: static unsigned int __cdecl std::numeric_limits::min(void)” (?min@?$numeric_limits@I@std@@SAIXZ) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 101 error LNK2005: “public: static unsigned int __cdecl std::numeric_limits::max(void)” (?max@?$numeric_limits@I@std@@SAIXZ) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 116 error LNK2005: “public: static unsigned int __cdecl std::char_traits::length(char const *)” (?length@?$char_traits@D@std@@SAIPBD@Z) already defined in common.obj msvcprtd.lib
    Error 114 error LNK2005: “public: static __int64 __cdecl std::numeric_limits::min(void)” (?min@?$numeric_limits@_J@std@@SA_JXZ) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 113 error LNK2005: “public: static __int64 __cdecl std::numeric_limits::max(void)” (?max@?$numeric_limits@_J@std@@SA_JXZ) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 137 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::substr(unsigned int,unsigned int)const ” (?substr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV12@II@Z) already defined in curl_wrapper.obj msvcprtd.lib
    Error 118 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > & __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::operator=(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)” (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@ABV01@@Z) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 105 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > & __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::operator=(char const *)” (??4?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in common.obj msvcprtd.lib
    Error 103 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > & __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::operator+=(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)” (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@ABV01@@Z) already defined in download_all_script_object.obj msvcprtd.lib
    Error 104 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > & __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::operator+=(char const *)” (??Y?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV01@PBD@Z) already defined in download_all_script_object.obj msvcprtd.lib
    Error 99 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > & __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::erase(unsigned int,unsigned int)” (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z) already defined in common.obj msvcprtd.lib
    Error 143 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > & __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::assign(char const *,unsigned int)” (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z) already defined in common.obj msvcprtd.lib
    Error 147 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > & __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::assign(char const *)” (?assign@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBD@Z) already defined in common.obj msvcprtd.lib
    Error 138 error LNK2005: “public: class std::basic_string<char,struct std::char_traits,class std::allocator > & __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::append(char const *,unsigned int)” (?append@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@PBDI@Z) already defined in download_all_script_object.obj msvcprtd.lib
    Error 135 error LNK2005: “public: class std::_String_iterator<char,struct std::char_traits,class std::allocator > __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::end(void)” (?end@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE?AV?$_String_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ) already defined in curl_wrapper.obj msvcprtd.lib
    Error 136 error LNK2005: “public: class std::_String_iterator<char,struct std::char_traits,class std::allocator > __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::begin(void)” (?begin@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE?AV?$_String_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ) already defined in curl_wrapper.obj msvcprtd.lib
    Error 132 error LNK2005: “public: class std::_String_const_iterator<char,struct std::char_traits,class std::allocator > __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::end(void)const ” (?end@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 133 error LNK2005: “public: class std::_String_const_iterator<char,struct std::char_traits,class std::allocator > __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::begin(void)const ” (?begin@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV?$_String_const_iterator@DU?$char_traits@D@std@@V?$allocator@D@2@@2@XZ) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 102 error LNK2005: “public: char const * __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::c_str(void)const ” (?c_str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ) already defined in common.obj msvcprtd.lib
    Error 127 error LNK2005: “public: char * __thiscall std::allocator::allocate(unsigned int)” (?allocate@?$allocator@D@std@@QAEPADI@Z) already defined in common.obj msvcprtd.lib
    Error 106 error LNK2005: “public: bool __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::empty(void)const ” (?empty@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE_NXZ) already defined in download_all_script_object.obj msvcprtd.lib
    Error 122 error LNK2005: “public: __thiscall std::basic_string<wchar_t,struct std::char_traits,class std::allocator >::basic_string<wchar_t,struct std::char_traits,class std::allocator >(wchar_t const *)” (??0?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@PB_W@Z) already defined in curl_wrapper.obj msvcprtd.lib
    Error 121 error LNK2005: “public: __thiscall std::basic_string<wchar_t,struct std::char_traits,class std::allocator >::~basic_string<wchar_t,struct std::char_traits,class std::allocator >(void)” (??1?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@QAE@XZ) already defined in curl_wrapper.obj msvcprtd.lib
    Error 148 error LNK2005: “public: __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::basic_string<char,struct std::char_traits,class std::allocator >(void)” (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in common.obj msvcprtd.lib
    Error 97 error LNK2005: “public: __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::basic_string<char,struct std::char_traits,class std::allocator >(class std::basic_string<char,struct std::char_traits,class std::allocator > const &)” (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) already defined in common.obj msvcprtd.lib
    Error 117 error LNK2005: “public: __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::basic_string<char,struct std::char_traits,class std::allocator >(char const *,unsigned int)” (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDI@Z) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 98 error LNK2005: “public: __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::basic_string<char,struct std::char_traits,class std::allocator >(char const *)” (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) already defined in common.obj msvcprtd.lib
    Error 96 error LNK2005: “public: __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::~basic_string<char,struct std::char_traits,class std::allocator >(void)” (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) already defined in common.obj msvcprtd.lib
    Error 125 error LNK2005: “public: __thiscall std::allocator::allocator(void)” (??0?$allocator@D@std@@QAE@XZ) already defined in common.obj msvcprtd.lib
    Error 126 error LNK2005: “public: __thiscall std::allocator::allocator(class std::allocator const &)” (??0?$allocator@D@std@@QAE@ABV01@@Z) already defined in common.obj msvcprtd.lib
    Error 144 error LNK2005: “public: __thiscall std::_String_val<char,class std::allocator >::~_String_val<char,class std::allocator >(void)” (??1?$_String_val@DV?$allocator@D@std@@@std@@QAE@XZ) already defined in common.obj msvcprtd.lib
    Error 108 error LNK2005: “public: __thiscall std::_Lockit::~_Lockit(void)” (??1_Lockit@std@@QAE@XZ) already defined in libcpmtd.lib(xlock.obj) msvcprtd.lib
    Error 109 error LNK2005: “public: __thiscall std::_Lockit::_Lockit(int)” (??0_Lockit@std@@QAE@H@Z) already defined in libcpmtd.lib(xlock.obj) msvcprtd.lib
    Error 111 error LNK2005: “public: __thiscall std::_Container_base_secure::~_Container_base_secure(void)” (??1_Container_base_secure@std@@QAE@XZ) already defined in common.obj msvcprtd.lib
    Error 112 error LNK2005: “public: __thiscall std::_Container_base_secure::_Container_base_secure(void)” (??0_Container_base_secure@std@@QAE@XZ) already defined in common.obj msvcprtd.lib
    Error 145 error LNK2005: “protected: void __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::_Tidy(bool,unsigned int)” (?_Tidy@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IAEX_NI@Z) already defined in common.obj msvcprtd.lib
    Error 134 error LNK2005: “protected: char * __thiscall std::basic_string<char,struct std::char_traits,class std::allocator >::_Myptr(void)” (?_Myptr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IAEPADXZ) already defined in common.obj msvcprtd.lib
    Error 146 error LNK2005: “protected: __thiscall std::_String_val<char,class std::allocator >::_String_val<char,class std::allocator >(class std::allocator)” (??0?$_String_val@DV?$allocator@D@std@@@std@@IAE@V?$allocator@D@1@@Z) already defined in common.obj msvcprtd.lib
    Error 119 error LNK2005: “class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl std::operator+<char,struct std::char_traits,class std::allocator >(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)” (??$?HDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@ABV10@0@Z) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 120 error LNK2005: “class std::basic_string<char,struct std::char_traits,class std::allocator > __cdecl std::operator+<char,struct std::char_traits,class std::allocator >(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,char const *)” (??$?HDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@ABV10@PBD@Z) already defined in torrent_wrapper.obj msvcprtd.lib
    Error 142 error LNK2005: “bool __cdecl std::operator<<char,struct std::char_traits,class std::allocator >(class std::basic_string<char,struct std::char_traits,class std::allocator > const &,class std::basic_string<char,struct std::char_traits,class std::allocator > const &)” (??$?MDU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@0@Z) already defined in script_object_base.obj msvcprtd.lib

    • softz says:

      Hi,

      Did you compile with statically linked library setting and /MD? This may be the cause of the problem. You can try compiling with dynamically linked library with /MDd for debug.

      Alternatively, you can add “/FORCE:MULTIPLE” in the Project Properties->Configuration Properties->Linker->Command Line and in the Additional Options box.

      • Ragu says:

        Hi,

        It is working now . i have compiled libtorrent with /MD option and my dll with /MTd option. i used /MDd in my both projects

        Thanks

  35. liwf says:

    hi
    i have compiled the libtorrent.lib(0.16.9) as a static library.but when i test the dump_client.exe in its examples ,it always crashes. It crashes in ” torrent_info t(e, ec) function ;” do you know why?
    thank you .

    • softz says:

      Hi,
      I’ve not tried much on the examples. But, I did encounter some crashes in their examples last time.

      • liwf says:

        hi.
        This week,i also tested the client_test.exe in the example.Although it could work, it occurs many menmory leaks.
        Do you konw some open projects based on libtorrent in windows?thank you very much.

        • softz says:

          Hi,
          Sorry for the late reply. There are several projects using libtorrent actually. You can refer to this url link: http://www.libtorrent.org/projects.html

        • softz says:

          Hi,

          Did you run through the client_test.exe for a period of time? Any incoming and outgoing connections require memory allocation. So, there will be an initial spike of memory. Thereafter, it’ll be stable.

          • liwf says:

            Hi,
            OK,i know it.
            Now,i am studying the libtorrent`s source codes,especially the codes about Local
            service discovery and DHT,are you family with these?
            Before,i thought Local service discovery was designed for one peer to discovery local BitTorrent peers initiativly when it want to download,but now i am doubbing whether i am right.

          • softz says:

            Hi,

            Local Service Discovery a.k.a Local Peer Discovery (LPD) works in a local area network to minimize the bandwidth through the ISP because it doesn’t go through the tracker. A good example will be within a school campus network. So basically, when your torrent client goes online, you make a broadcast to the local network. If there are existing peers, they will start connecting to you and sending/receiving takes place. In fact, every peers broadcast themselves every 4-5 mins.

            DHT works similarly like a Tracker with the exception that DHT is public and Tracker is more private (information is only found in the torrent file). You still send your http-GET/POST to the tracker to get a list of peers based on the info-hash. For further explanation, you can read from here (http://www.maketecheasier.com/how-bittorrent-dht-peer-discovery-works/)

            I hope I manage to answer your questions.

  36. ameline says:

    Thank you very much for this tutorial. I have been trying to build libtorrent since 3 days without success, and finally it’s working. Thank you, awesome tutorial!

  37. Mick says:

    Hi there, do you think you could email me the compiled dll file without debug and with DHT please? have tried for two weeks to build 0.16.13 without any success lol.

    Also I dont know if you know the LuaTorrent project or not, it uses an old LibTorrent build, but do you think thats something you could update?

  38. Vladimir says:

    Hey can you send me libtorrent.dll and libtorrent.lib for email – amal_gama@mail.ru
    Thx for great work!!!!

  39. Keldo says:

    Hey, I cannot get this to Compile, different errors on each attempt, I followed your example to the letter. Can I get you to send me the lib and dll as well?
    scott at twedev dot com

  40. Chris says:

    Hi softz, I’m having trouble building the lib torrent dll after following this tutorial. Can you please send me the lib and dll files if possible? Thanks!

  41. Tâm says:

    Hi softz,

    HI, I follow your tutorial, and I use vs2012,boost_1_55_0,libtorrent-rasterbar-1.0.1

    but when compile it give me this error:

    Creating library D:\Working\Research\libtorrent\Mytorrent\Release\Mytorrent.lib and object D:\Working\Research\libtorrent\Mytorrent\Release\Mytorrent.exp
    1>item.obj : error LNK2001: unresolved external symbol _ed25519_sign
    1>item.obj : error LNK2001: unresolved external symbol _ed25519_verify
    1>D:\Working\Research\libtorrent\Mytorrent\Release\Mytorrent.dll : fatal error LNK1120: 2 unresolved externals

    Thanks,

    Tâm.

    • softz says:

      It seems like you are missing some implementation for the item object which causes the linking error. Let me try out with those versions you mention this weekend.

    • softz says:

      Very sorry for the so late reply.

      There isn’t any problem. Everything compiles fine. I used boost_1_57_0 and libtorrent-rasterbar-0.16.13. Did you miss out including any libraries?

  42. Mike says:

    Hi, struggling with this, could you share a compiled dll that has DHT and debug off?

    Thanks.

Leave a Reply to LoopBack


nine + = 16