交叉编译总结

近来交叉编译的需求越来越多, 不管是开源的程序还是自己的程序都想交叉编译到开发板上。交叉编译多个project以后发现常见的方式就三种(仅限于我经手的)。

通过configure配置的

export PATH=$PATH:$PATH_TO_CROSS_COMPILE_TOOL
./configure --host=aarch64-linux-gnu

make && make install

直接Makefile的

export PATH=$PATH:$PATH_TO_CROSS_COMPILE_TOOL
export CC=aarch64-linux-gnu-gcc
export CXX=aarch64-linux-gnu-g++
export LD=aarch64-linux-gnu-ld
export AR=aarch64-linux-gnu-ar
export RANLIB=aarch64-linux-gnu-ranlib

make && make install

通过cmake 组织的

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_FIND_ROOT_PATH "/data/Xilinx/zcu102_rv_ss/sw/sysroot")
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET(CMAKE_C_COMPILER "$PATH_TO_CROSS_COMPILE_TOOL/aarch64-linux-gnu-gcc")
SET(CMAKE_CXX_COMPILER "$PATH_TO_CROSS_COMPILE_TOOL/aarch64-linux-gnu-g++")

cmake .. && make && make install