Skip to content

Building on Windows

inb4 nyssa edited this page Apr 6, 2015 · 6 revisions

Building on Windows

Introduction

This guide covers building on Windows using MSYS2. It will cover building Boost from source and installing the libraries, building libtorrent-1.0 from source and installing the libraries, building OpenSSL 1.0.1h from source, and finally building gTorrent itself. It will NOT cover building GTK from source. If you run into any problems or see any mistakes in this guide, feel free to contact me (ragesalmon) on either github or IRC. Finally, a big shoutout to shinigamichan, who was the first to get gTorrent building on Windows with a working GUI and put up with my questions in the IRC.

Installing Prerequisites

MSYS2 and MinGW-w64

MSYS2 provides us with a suitable build environment for gTorrent's dependencies. You can download MSYS2 from here: http://sourceforge.net/projects/msys2/files/Base/x86_64/

Make sure to grab the latest version. Note: the version of MSYS we will be working with is the 64-bit version. If you would like to build in a 32-bit environment, use common sense replace all occurrences of x64 in this guide with i686.

Once you download the latest version of MSYS2, either extract or install it to the directory of your choosing. This guide will assume you are extracting it to C:\MSYS.

Once it is extracted, open up the C:\MSYS\ directory and run the file titled "mingw64_shell.bat". This should open up a shell. Inside the shell, execute the following commands:

pacman -Syu
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-pkgconf make

Follow the prompts and install the toolchain and make. Next are some more "optional" installs, but if you don't already have these set up in your environment, it is recommended that you install them now:

pacman -S git mingw-w64-x86_64-cmake-git

This should install git and cmake and make them usable to you from the command line, if you don't already have them configured in windows. With that, you should have a working MSYS2/MinGW-w64-x86_64 build environment.

Installing Boost and Boost.Build

Boost is an extremely useful C++ library that libtorrent depends on. Now we will install both the Boost Library and its build tools, which we will use to build libtorrent. Download the latest release of Boost from here: http://www.boost.org/.

Extract the library somewhere. This guide assumes you extract it to ~/boost.

Cd into your Boost directory and issue the following commands:

./bootstrap.bat gcc
./b2 -j$NUMBER_OF_PROCESSORS --prefix=/mingw64/ toolset=gcc variant=release link=static threading=multi runtime-link=shared -a install

These commands should install the Boost libraries to "/mingw64/lib" and "/mingw64/include". However, by default, the header files cannot be found by compilers because they are not in "/mingw64/include/boost", but rather "/mingw64/include/boost-{latest boost version}/boost". To remedy this, simply copy the "boost" folder in "/mingw64/include/boost_{latest boost version}" to the directory above it, namely "/mingw64/include/". To check that the Boost libraries are available to the compilers, execute the following commands:

cd ~
echo "#include <boost/utility.hpp>" > boost.cpp && g++ boost.cpp

If you see an error message warning about an "undefined reference to WinMain" (sp) function, then boost was found and we are ready to build the Boost Build Tools.

cd back into "~/boost", and then into "tools/build/v2". In this directory, issue the following commands:

./bootstrap.bat gcc
./b2 --prefix=/mingw64/ install

This will install the "bjam" and "b2" executables and make them available from the command line.

Installing OpenSSL

Astute readers may have noticed that while installing mingw-w64-x86_64-toolchain, we installed a package for openssl. However, that package does not provide "ssleay32.dll" or "libeay32.dll", which libtorrent needs to be linked against, so we need to build openssl from source. To do this, download and extract the latest openssl package from here: https://www.openssl.org/source/ (the one next to [LATEST])

Extract the tarball to a convenient directory. This guide assumes it is extracted to "~/openssl".

Cd into "~/openssl" and run the following commands:

./configure --prefix=/mingw64/ threads zlib-dynamic shared mingw64
mingw32-make depend -j$NUMBER_OF_PROCESSORS
mingw32-make -j$NUMBER_OF_PROCESSORS
mingw32-make install 

This should install most of the openSSL files to the right places. However, you may need to copy "libeay32.dll" and "ssleay32.dll" to both "/mingw64/bin" and "/mingw64/lib".

Installing libtorrent

Libtorrent is the library that gTorrent uses to download torrents. Download the 1.0.1 release (http://sourceforge.net/projects/libtorrent/files/latest/download?source=files) and extract it. This guide assumes that it is extracted to ~/libtorrent-1.0.1/

CD into ~/libtorrent-1.0.1/ and run the following commands:

./configure --prefix=/mingw64/ --enable-geoip=no --enable-tests=no --enable-debug=no --enable-shared=yes --enable-encryption --with-boost-system=mgw49-mt-1_55 # Note: the boost libraries all have a suffix appended to them based on the build system and options used. If you followed this guide, then the provided suffix should be sufficient. However, double check "/mingw64/lib" just to be sure

This should configure libtorrent and make it ready to build. However, we are not really using autotools, so this step is mostly just to check that everything is in the right place. Next, issue the following command:

b2 -j$NUMBER_OF_PROCESSORS toolset=gcc link=shared runtime-link=shared boost=system variant=release dht=on geoip=static encryption=openssl --prefix=/mingw64/ -a install
cat ./libtorrent-rasterbar.pc | sed -e "s/-ltorrent-rasterbar/-ltorrent/g" > /mingw64/lib/pkgconfig/libtorrent-rasterbar.pc

If you get an error about ld.exe not being able to find "-lssleay32", "-llibeay32", "-lboost_system", go back in to your openssl directory, and copy both "libeay32.dll" and "ssleay32.dll" to "/mingw64/lib". In "/mingw64/lib", copy libboost_system-mgw49... to libboost_system.a. Rerun the above command, and it should build.

With a bit of luck, this should install libtorrent properly.

Install gTorrent

Congratulations! If everything worked so far, you are ready to install gTorrent. Clone the repo in to your home directory with the following command:

git clone https://github.com/gtorrent/gTorrent.git ~/gTorrent -b no-gui
cd ~/gTorrent

NOTE: A vim window might open up during this step. Ignore it and enter ":q!" to quit it

This will clone the repository to ~/gTorrent. CD into that directory and make a folder called "build". CD into the "build" directory and run the following:

cmake -G "MSYS Makefiles" ..
mingw32-make -j$NUMBER_OF_PROCESSORS

If this works, you should be able to run ./gtorrent.exe from the command line! Congratulations, gTorrent is built and you are ready to contribute. NOTE: There is currently an issue running gTorrent from MSYS. In order to run it from outside of MSYS, you have either two choices: add /mingw64/bin to your Windows PATH variable, or you can copy each of the required DLLs from /mingw64/bin to your gtorrent/Build folder.