mac 电脑上交叉编译n2n,目标机arm linux
下载openssl-1.0.2p,并交叉编译openssl,openssl的安装目录/opt/ssh/openssl-1.0.2p/_install
git clone https://github.com/meyerd/n2n.git
brew install cmake
~/n2n/n2n_v2$ mkdir build
~/n2n/n2n_v2$ cd build
编辑~/n2n/2n2_v2/CMakeLists.txt,找到set(CMAKE_C_FLAGS 和set(CMAKE_CXX_FLAGS 两行
在这两行的里面括号里面的部分, 加入编译参数-I /opt/ssh/openssl-1.0.2p/_install/include -L /opt/ssh/openssl-1.0.2p/_install/lib
修改的内容如下:
# None
if(NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs -fPIC -I /opt/ssh/openssl-1.0.2p/_install/include -L /opt/ssh/openssl-1.0.2p/_install/lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wshadow -Wpointer-arith -Wmissing-declarations -Wnested-externs -I /opt/ssh/openssl-1.0.2p/_install/include -L /opt/ssh/openssl-1.0.2p/_install/lib")
# Debug
set(CMAKE_C_FLAGS_DEBUG "-g -fsanitize=address")
set(CMAKE_CXX_FLAGS_DEBUG "-g -fsanitize=address")
# Release
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
endif(NOT WIN32)
#for macOS, add openssl include dir
if(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I /opt/ssh/openssl-1.0.2p/_install/include -L /opt/ssh/openssl-1.0.2p/_install/lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I /opt/ssh/openssl-1.0.2p/_install/include -L /opt/ssh/openssl-1.0.2p/_install/lib")
endif(APPLE)
~/n2n/n2n_v2/build$ cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/am335x_armlinux_cmake.cmake --build ./ ../
~/n2n/n2n_v2/build$ make
没有设置openssl的编译路径的话, 编译到transform_aes.c.o会有提示错误openssl/aes.h: No such file or directory
~/n2n/n2n_v2/cmake/am335x_armlinux_cmake.cmake内容如下:
# the name of the target operating system
SET(CMAKE_SYSTEM_NAME Linux)
SET(OPENSSL_ROOT_DIR /opt/ssh/openssl-1.0.2p/_install)
# which compilers to use for C and C++
SET(CMAKE_C_COMPILER /Volumes/linux/gcc4.7.3-arm-linux-gnueabihf/install/bin/arm-cortex_a8-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER /Volumes/linux/gcc4.7.3-arm-linux-gnueabihf/install/bin/arm-cortex_a8-linux-gnueabihf-g++)
# here is the target environment located
SET(CMAKE_FIND_ROOT_PATH /Volumes/linux/gcc4.7.3-arm-linux-gnueabihf/install /opt/ssh/openssl-1.0.2p/_install)
# 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)