User Tools

Site Tools


tor:tor_for_windows

TOR Executabe for Windows

In a project I needed to have statically built tor.exe (single executable) for windows. Official tor expert bundle distribution has many dll files which is undesirable for my needs. So I compiled it under windows using mingw and msys for x86 architecture. Since it is a tedious job to compile all tor dependencies and tor, I put it here for good. Zip file includes only tor.exe, tor-gencert.exe and tor-resolve.exe as well. If you don't need tor-gencert.exe and tor-resolve.exe, you can delete them.

Download Links

tor_static-v0.2.8.9.zip

tor_static-v0.2.7.6.zip

How to Compile Tor using MinGW

Building TOR having a static executable is described below. If you are familiar with Linux shells, it is easier for you. Follow the instructions below. If you have any problem, do not hesitate to ask. I put lots of environment variables and compiler/linker flags to be on the safe side even if they are useless. Let me know if anything is unnecessary. If you do not need a static executable, just visit tor website and download tor expert bundle.

tor_build_instructions.txt
# November 2016
# these instructions are for x86 computers, for x64 you know what to do :)
# install msys2 from http://msys2.github.io/
# after installation, open msys2 console and install some useful packages (msys2.exe)
# visit wiki pages of msys2 for further information
pacman -Syu # probably you should run this update command for two times to get all updates
pacman -S msys/make msys/perl msys/tar
pacman -S mingw32/mingw-w64-i686-binutils msys/binutils
pacman -S mingw32/mingw-w64-i686-gcc
pacman -S mingw32/mingw-w64-i686-make
pacman -S msys/pkg-config mingw32/mingw-w64-i686-pkg-config
 
# change console to mingw32 console (mingw32.exe)
# download required libraries for build process (openssl,zlib,libevent)
# Currently I cannot compile tor with openssl version greater than 1.0.2j
wget https://www.openssl.org/source/openssl-1.0.2j.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
wget https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
wget https://www.torproject.org/dist/tor-0.2.8.9.tar.gz
mkdir openssl && mkdir libevent && mkdir zlib && mkdir tor
tar xzf openssl-1.0.2j.tar.gz -C openssl
tar xzf zlib-1.2.8.tar.gz -C zlib
tar xzf libevent-2.0.22-stable.tar.gz -C libevent
tar xzf tor-0.2.8.9.tar.gz -C tor
 
# you may set these environment variables for compiling zlib
export INCLUDE_PATH="/mingw32/include:/mingw32/i686-w64-mingw32/include:$INCLUDE_PATH"
export LIBRARY_PATH="/mingw32/lib:/mingw32/i686-w64-mingw32/lib:$LIBRARY_PATH"
export BINARY_PATH="/mingw32/bin:/mingw32/i686-w64-mingw32/bin:$BINARY_PATH"
 
# compile zlib
cd ~/zlib/zlib-1.2.8
make -fwin32/Makefile.gcc
 
# compile libevent
cd ~/libevent/libevent-2.0.22-stable
./configure --prefix="$HOME/libevent/install" --enable-static --disable-shared
make
make install
 
# compile openssl (if you don't have a fast computer, this may take a long time)
# -static-libgcc flag may be redundant with -static but just in case.
cd ~/openssl/openssl-1.0.2j
LDFLAGS="-static -static-libgcc" ./Configure no-shared no-zlib no-asm --prefix="$HOME/openssl/install" -static mingw
make depend && make && make install
 
# now it is time to compile tor if everything is OK above
cd ~/tor/tor-0.2.8.9
 
export LDFLAGS="-static -static-libgcc -L$HOME/openssl/install/lib -L$HOME/libevent/install/lib -L$HOME/zlib/zlib-1.2.8 -L/mingw32/lib -L/mingw32/i686-w64-mingw32/lib"
export CFLAGS="-I$HOME/openssl/install/include -I$HOME/zlib/zlib-1.2.8 -I$HOME/libevent/install/include"
export LIBRARY_PATH="$HOME/openssl/install/lib:$HOME/libevent/install/lib:$HOME/zlib/zlib-1.2.8:/mingw32/lib:/mingw32/i686-w64-mingw32/lib"
export INCLUDE_PATH="$HOME/openssl/install/include:$HOME/zlib/zlib-1.2.8:$HOME/libevent/install/include:/mingw32/include:/mingw32/i686-w64-mingw32/include"
export BINARY_PATH="/mingw32/bin:/mingw32/i686-w64-mingw32/bin"
export PKG_CONFIG_PATH="$HOME/openssl/install/lib/pkgconfig:$PKG_CONFIG_PATH"
 
# this is important if -lcrypt32 is omitted, you may get linker error
export LIBS="-lcrypt32"
 
./configure --disable-gcc-hardening --enable-static-tor --prefix="$HOME/tor/install" --with-libevent-dir="$HOME/libevent/install/lib" --with-openssl-dir="$HOME/openssl/install/lib" --with-zlib-dir="$HOME/zlib/zlib-1.2.8"
make
make install
 
# The configuration parameter "--disable-gcc-hardening" builds Tor without requiring
# the libssp-0.dll. If you build without this parameter then don't forget to copy
# libssp-0.dll from /mingw32/bin to the folder where tor.exe is located. libssp is
# a library for stack protection.

As Marisol stated in discussion section below, make install-strip produces smaller size executables.

Discussion

Sherif, 2016/11/11 04:32

Thanks. It would be really helpful if you could share how you did it.

Ozan HACIBEKIROGLU, 2016/11/13 19:53

Hello, I will write a tutorial within this week and share it. Please, follow this page.

Sherif, 2016/11/14 02:29

Looking forward to it. Thanks!

Ozan HACIBEKIROGLU, 2016/11/17 06:57

I have added build instructions, please check them and let me know if everything is OK

Marisol, 2017/04/12 10:48

Great Guide. Following it, I managed to compile Tor 0.2.9.10 for Windows. However, in last step it would be better to use command “make install-strip” – the resulting exe will be less in size and without debugging symbols.

Ozan HACIBEKIROGLU, 2017/04/12 19:51

I am glad it is helpful Marisol. I will update the guide accordingly.

Peter, 2017/12/02 08:50

Your guide is excellent. I've compiled 0.2.9.14 with zlib-1.2.11, works gr8. Thank U very much.

Ozan HACIBEKIROGLU, 2017/12/02 09:39

Your are welcome thank you

Enter your comment. Wiki syntax is allowed:
 
tor/tor_for_windows.txt · Last modified: 2017/04/13 06:16 by ozan