Home

Awesome

tor-static Build Status Build status

This project helps compile Tor into a static lib for use in other projects.

The dependencies are in this repository as submodules so this repository needs to be cloned with --recursive. The submodules are:

Many many bugs and quirks were hit while deriving these steps. Also many other repos, mailing lists, etc were leveraged to get some of the pieces right. They are not listed here for brevity reasons.

Note: Other versions of Tor may be available via tags (for current or previous versions) and branches (for future versions)

Building

Prerequisites

All platforms need Go installed and on the PATH.

Linux

Need:

macOS

Need:

Windows

Tor is not really designed to work well with MSVC so we use MinGW instead. In order to compile the dependencies, Msys2 + MinGW should be installed.

Download and install the latest MSYS2 64-bit that uses the MinGW-w64 toolchains. Once installed, open the "MSYS MinGW 64-bit" shell link that was created. Once in the shell, run:

pacman -Syuu

Terminate and restart the shell if asked. Rerun this command as many times as needed until it reports that everything is up to date. Then in the same mingw-64 shell, run:

pacman -Sy --needed base-devel mingw-w64-i686-toolchain mingw-w64-x86_64-toolchain \
                    git subversion mercurial libtool automake autoconf automake-wrapper \
                    mingw-w64-i686-cmake mingw-w64-x86_64-cmake

This will install all the tools needed for building and will take a while. Once complete, MinGW is now setup to build the dependencies.

Executing the build

In the cloned directory, run:

go run build.go build-all

This will take a long time. Pieces can be built individually by changing the command from build-all to build-<folder>. To clean, run either clean-all or clean-<folder>. To see the output of all the commands as they are being run, add -verbose before the command.

Using

Once the libs have been compiled, they can be used to link with your program. Due to recent refactorings within the Tor source, the libraries are not listed here but instead listed when executing:

go run build.go show-libs

This lists directories (relative, prefixed with -L) followed by lib names (file sans lib prefix and sans .a extension, prefixed with -l) as might be used in ld.

The OS-specific system libs that have to be referenced (i.e. -l<libname>) are:

The OS-specific system libs that have to be explicitly statically linked (i.e. -Wl,-Bstatic -l<libname>) are: