Skip to content
Bishop Clark edited this page Nov 11, 2018 · 2 revisions
# ### ### 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
macOS Before build, you must install openssl library:
brew install openssl
Generate makefiles:

~/n2n$ mkdir build
~/n2n$ cd build
~/n2n/build$ cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ../
-- The C compiler identification is AppleClang 8.1.0.8020042
-- The CXX compiler identification is AppleClang 8.1.0.8020042
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /usr/local/opt/openssl/lib/libcrypto.dylib (found version "1.0.2l")
-- Configuring done
-- Generating done
-- Build files have been written to: ~/n2n/n2n_v2/build
Generate Xcode project:
~/n2n$ mkdir build
~/n2n$ cd build
~/n2n/build$ cmake -G "Xcode" -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ../
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
Cross compiling on Ubuntu for Windows # install mingw
sudo apt-get install g++-mingw-w64 gcc-mingw-w64 mingw-w64
# edit cmake file
vim n2n_v2/cmake/CMakeToolchainFileMingw32.cmake
# TODO: do as above Cross compiling on Linux for Win32

n2n_v2/cmake/CMakeToolchainFileMingw32.cmake content:


# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Windows)

# which compilers to use for C and C++
# SET(CMAKE_C_COMPILER i686-mingw32-gcc)
SET(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
# SET(CMAKE_CXX_COMPILER i686-mingw32-g++)
SET(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)

# here is the target environment located
# SET(CMAKE_FIND_ROOT_PATH ${HOME}/win_n2n/mingw32/)
SET(CMAKE_FIND_ROOT_PATH /usr/bin/)

# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search 
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Clone this wiki locally