1 [[!meta title="cross-compiling tinc for 64-bit Windows under Linux using MinGW"]]
3 ## Howto: cross-compiling tinc for Windows under Linux using MinGW
5 This howto describes how to create a 64-bit Windows binary of tinc. Although it is
6 possible to compile tinc under Windows itself, cross-compiling it under Linux
7 is much faster. It is also much easier to get all the dependencies in a modern
8 distribution. Therefore, this howto deals with cross-compiling tinc with MinGW
9 under Linux on a Debian distribution.
15 * Install 64-bit MinGW.
16 * Create a directory where we will perform all cross-compilations.
17 * Get all the necessary sources.
18 * Cross-compile everything.
20 ### Installing the prerequisites for cross-compilation
22 There are only a few packages that need to be installed as root to get started:
24 sudo apt-get install mingw-w64 git-core wget
25 sudo apt-get build-dep tinc
27 Other Linux distributions may also have 64-bit MinGW packages, use their respective
28 package management tools to install them. Debian installs the cross-compiler
29 in `/usr/x86_64-w64-mingw32/`. Other distributions might install it in another
30 directory however. Check in which directory
31 it is installed, and replace all occurences of `x86_64-w64-mingw32` in this
32 example with the correct name from your distribution.
34 ### Setting up the build directory and getting the sources
36 We will create a directory called `mingw64/` in the home directory. We use
37 apt-get and wget to get the required libraries necessary for tinc, and use
38 `git` to get the latest development version of tinc.
42 apt-get source liblzo2-dev zlib1g-dev libssl-dev
43 git clone git://tinc-vpn.org/tinc
45 ### Making cross-compilation easy
47 To make cross-compiling easy, we create a script called `mingw64` that will set
48 up the necessary environment variables so configure scripts and Makefiles will
49 use the 64-bit MinGW version of GCC and binutils:
52 cat >$HOME/bin/mingw64 << EOF
54 PREFIX=x86_64-w64-mingw32
56 export CXX=$PREFIX-g++
57 export CPP=$PREFIX-cpp
58 export RANLIB=$PREFIX-ranlib
59 export PATH="/usr/x86_64-w64-mingw32/bin:$PATH"
62 chmod u+x $HOME/bin/mingw64
64 If `$HOME/bin` is not already part of your `$PATH`, you need to add it:
66 export PATH="$HOME/bin:$PATH"
68 We use this script to call `./configure` and `make` with the right environment
69 variables, but only when the `./configure` script doesn't support cross-compilation itself.
70 You can also run the export commands from the `mingw64` script by
71 hand instead of calling the mingw64 script for every `./configure` or `make`
72 command, or execute `$HOME/bin/mingw64 $SHELL` to get a shell with these
73 environment variables set, but in this howto we will call it explicitly every
78 Cross-compiling LZO is easy:
80 cd $HOME/mingw64/lzo2-2.06
81 ./configure --host=x86_64-w64-mingw32
83 DESTDIR=$HOME/mingw64 make install
85 If it fails with a message about not passing the "ACC" test,
86 create a symlink for the missing getopt.h file as mentioned above.
90 Cross-compiling Zlib is also easy, but a plain `make` failed to compile the
91 tests, so we only build the static library here:
93 cd $HOME/mingw64/zlib-1.2.7.dfsg
94 mingw64 ./configure --static
96 DESTDIR=$HOME/mingw64 mingw64 make install
100 Although older versions will not compile, OpenSSL 1.0.0 is easy.
101 However, `apt-get source` will have applied
102 Debian-specific patches that break cross-compiling a Windows binary.
103 You need to undo those patches first.
104 Do not use the `-j` option when compiling OpenSSL, it will break.
106 cd $HOME/mingw64/openssl-1.0.1c
108 mingw64 ./Configure --openssldir=$HOME/mingw64/usr/local mingw64
114 Now that all the dependencies have been cross-compiled, we can cross-compile
115 tinc. Since we use a clone of the git repository here, we need to run
116 `autoreconf` first. If you want to cross-compile tinc from a released tarball,
117 this is not necessary.
119 cd $HOME/mingw64/tinc
121 ./configure --host=x86_64-w64-mingw32 --with-openssl=$HOME/mingw64/usr/local