中文 English

How to run N2N-compilation using Windows

Published: 2021-01-15
network N2N Windows tap tapwindows

According to Building说明 of N2N官方网站, the software required for Windows compilation is Visual Studio,Cmake,OpenSSL

I got a headache when I saw Visual Studio. This software is very difficult to install. So I chose cross-compilation, that is, using the Linux environment to compile Windows exe and dll files.

#Compiled files

Compilation environment:

Contains edge, supernode, openssl链接库 (necessary for n2n operation), tap-windows安装包 (necessary for n2n operation, Win7&Win10)

Prepare the compilation environment

wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/Windows/edge.exe -O edge
wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/Windows/supernode.exe -O supernode
wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/Windows/libcrypto-1_1-x64.dll -O libcrypto-1_1-x64.dll
wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/Windows/libssl-1_1-x64.dll -O libssl-1_1-x64.dll

OpenSSL cross-compilation

apt-get install mingw-w64
apt-get install cmake
apt-get install openssl
apt-get install libssl-dev
apt-get install build-essential git bison flex libxml2-dev libpcap-dev libtool libtool-bin rrdtool librrd-dev autoconf pkg-config automake autogen redis-server wget libsqlite3-dev libhiredis-dev libmaxminddb-dev libcurl4-openssl-dev libpango1.0-dev libcairo2-dev libnetfilter-queue-dev zlib1g-dev libssl-dev libcap-dev libnetfilter-conntrack-dev libreadline-dev libjson-c-dev libldap2-dev rename libsnmp-dev

Download N2N source code

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz
tar -xvzf openssl-1.1.1i.tar.gz
cd openssl-1.1.1i
CROSS_COMPILE="x86_64-w64-mingw32-"  ./Configure mingw64 no-asm -shared --prefix=/opt/toolchain/openssl/install-x86_64
make
make install

N2N cross compilation preparation

Create a new toolChain.cmake file in the n2n directory and enter the following configuration content

cd ~
git clone https://github.com/ntop/n2n
cd n2n
git checkout 2.8-stable

N2N cross compilation

Cross-compile n2n using CMake

cd ~/n2n
vim toolChain.cmake
SET(CMAKE_SYSTEM_NAME Windows)
SET(CMAKE_CROSSCOMPILING TRUE)
SET(CMAKE_CROSSCOMPILER "x86_64-w64-mingw32-")
SET(CMAKE_C_COMPILER "${CMAKE_CROSSCOMPILER}gcc")
SET(CMAKE_CXX_COMPILER "${CMAKE_CROSSCOMPILER}g++")
SET(CMAKE_FIND_ROOT_PATH /opt/toolchain/openssl/install-x86_64)
SET(CMAKE_VERBOSE_MAKEFILE on)

Install TapWindows 9.24.2

mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../toolChain.cmake ..
make

Optional, how to start multiple edge nodes on the same machine