Wednesday, August 11, 2010

Cross Compiling OpenVPN for Windows on Linux

I went through quite a struggle to build OpenVPN and a custom installer for Windows using my Linux machine. This post describes how to achieve this. To make it easier I packaged all the actual build steps into a script.

This post works on the cross compiling environment prepared in my previous post Building a Cross Compiler on Linux for MinGW32.

If you want to build the installer exe for OpenVPN as well, you will need NSIS (Nullsoft Installer System) installed. Download and compile it from

You will still be able to build the exes without NSIS. NSIS is only needed for packaging them into an installer.

Also note that this doesn't build the TAP driver. It just copies the prebuilt one. To do this would have to install the Microsoft DDK, make an amd64 cross compile environment and modify my script to build the driver instead of copying it.

First download the following:
  1. Prebuilt packages from Choose the latest -prebuilt .tbz file.
  2. Download the latest OpenVPN source code tar.gz archive.
  3. Download the build scripts from here.
Then extract the build scripts to your home directory. This will then create a directory ~/openvpn-src which contains ~/openvpn-src/archive. Copy the prebuilt and OpenVPN source code packages into ~/openvpn-src/archive.

Modify the ~/openvpn-src/ script to reflect your cross-compiler environment. The variables have the following purposes:
  • PREFIX - Where to install the compiled OpenVPN files
  • TARGET - The build environment you're targeting, for example i686-mingw32msvc
  • TOOLCHAIN - The root location where the cross compiler binaries are access from.
  • MAKENSIS - The full path to your makensis variable. Leave this empty if you don't want the installer to be created or if you don't have NSIS installed.
  • The rest of them are standard autoconf environment variables.
When you're ready you can kick of

The resulting OpenVPN .exe files will be located in the directory your PREFIX variable points to, which by default would be ~/openvpn-dist.

This script was tested with openvpn-2.1.1 and 2.1_rc22-prebuilt.tgz.

No comments: