Compilation

meyerd edited this page Sep 19, 2011 · 6 revisions
Clone this wiki locally

Compilation

CMake is the preferred method for compiling n2n.

Linux

Generate makefiles with CMake:

~/n2n$ mkdir build
~/n2n$ cd build
~/n2n/build$ cmake --build ./ ../
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: g++
-- Check for working CXX compiler: g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: ~/n2n/build
~/n2n/build$ make

Win32

Use the CMake GUI for creating the Visual Studio Project files or use the command line:

C:\n2n> mkdir build
C:\n2n> cd build
C:\n2n\build> cmake -G "Visual Studio 10" --build .\ ..\
-- Check for working C compiler using: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 10
-- Check for working CXX compiler using: Visual Studio 10 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/n2n/build

Then use the generated n2n.sln for compilation.

Cross compiling on Linux for Win32

You will need the mingw32 cross compiler suite. Install it as for example described here. If the installer script asks you whether it should use host libraries, answer NO.

Customize the file cmake/CMakeToolchainFileMingw32.cmake for your compiler installation, then generate the makefiles like this (the compiler binary is expected to be installed in $HOME/mingw32 and called i686-mingw32 in this example):

~/n2n$ mkdir build
~/n2n$ cd build
~/n2n/build$ export PATH="$PATH:$HOME/mingw32/bin"
~/n2n/build$ cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/CMakeToolchainFileMingw32.cmake --build ./ ../
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: ~/mingw32/bin/i686-mingw32-gcc
-- Check for working C compiler: ~/mingw32/bin/i686-mingw32-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: ~/mingw32/bin/i686-mingw32-g++
-- Check for working CXX compiler: ~/mingw32/bin/i686-mingw32-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: ~/n2n/build

Then build the executables with make:

~/n2n/build$ make
Scanning dependencies of target n2n_win32
[  4%] Building C object win32/CMakeFiles/n2n_win32.dir/getopt1.c.obj
[  9%] Building C object win32/CMakeFiles/n2n_win32.dir/getopt.c.obj
[ 13%] Building C object win32/CMakeFiles/n2n_win32.dir/wintap.c.obj
[ 18%] Building C object win32/CMakeFiles/n2n_win32.dir/n2n_win32.c.obj
Linking C static library libn2n_win32.a
[ 18%] Built target n2n_win32
Scanning dependencies of target n2n
[ 22%] Building C object CMakeFiles/n2n.dir/n2n.c.obj
[ 27%] Building C object CMakeFiles/n2n.dir/n2n_keyfile.c.obj
[ 31%] Building C object CMakeFiles/n2n.dir/wire.c.obj
[ 36%] Building C object CMakeFiles/n2n.dir/minilzo.c.obj
[ 40%] Building C object CMakeFiles/n2n.dir/twofish.c.obj
[ 45%] Building C object CMakeFiles/n2n.dir/transform_null.c.obj
[ 50%] Building C object CMakeFiles/n2n.dir/transform_tf.c.obj
[ 54%] Building C object CMakeFiles/n2n.dir/transform_aes.c.obj
[ 59%] Building C object CMakeFiles/n2n.dir/tuntap_freebsd.c.obj
[ 63%] Building C object CMakeFiles/n2n.dir/tuntap_netbsd.c.obj
[ 68%] Building C object CMakeFiles/n2n.dir/tuntap_linux.c.obj
[ 72%] Building C object CMakeFiles/n2n.dir/tuntap_osx.c.obj
[ 77%] Building C object CMakeFiles/n2n.dir/version.c.obj
Linking C static library libn2n.a
[ 77%] Built target n2n
Scanning dependencies of target benchmark
[ 81%] Building C object CMakeFiles/benchmark.dir/benchmark.c.obj
Linking C executable benchmark.exe
[ 81%] Built target benchmark
Scanning dependencies of target benchmark_hashtable
[ 86%] Building C object CMakeFiles/benchmark_hashtable.dir/benchmark_hashtable.c.obj
Linking C executable benchmark_hashtable.exe
[ 86%] Built target benchmark_hashtable
Scanning dependencies of target edge
[ 90%] Building C object CMakeFiles/edge.dir/edge.c.obj
Linking C executable edge.exe
[ 90%] Built target edge
Scanning dependencies of target supernode
[ 95%] Building C object CMakeFiles/supernode.dir/sn.c.obj
Linking C executable supernode.exe
[ 95%] Built target supernode
Scanning dependencies of target test
[100%] Building C object CMakeFiles/test.dir/test.c.obj
Linking C executable test.exe
[100%] Built target test