1、准备编译器和sysroot环境,下载地址为:https://releases.linaro.org/components/toolchain/binaries/latest/aarch64-linux-gnu/
- 编译器是:gcc-linaro-7.1.1-2017.08-x86_64_aarch64-linux-gnu.tar.xz
- sysroot是:sysroot-glibc-linaro-2.25-2017.08-aarch64-linux-gnu.tar.xz
2、解压缩上述两个压缩包,并将gcc编译器加入系统可执行程序搜索路径中
export PATH=$PATH:~/work/linaro/gcc-linaro-7.1.1-2017.08-x86_64_aarch64-linux-gnu/bin
3、根据网上提供的配置CMakelist进行交叉编译的方法,修改ncnn工程的主CMakelist.txt文件,在文件开头新增以下内容:
SET(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
SET(CMAKE_FIND_ROOT_PATH "~/work/linaro/sysroot-glibc-linaro-2.25-2017.08-aarch64-linux-gnu")
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 aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
SET(CMAKE_FIND_ROOT_PATH "~/work/linaro/sysroot-glibc-linaro-2.25-2017.08-aarch64-linux-gnu")
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
4、执行正常的编译操作,编译时会遇到类似错误: fatal error: opencv2/core/core.hpp: No such file or directory
此时需要先将opencv交叉编译,将编译完成的库和头文件放到systroot目录即可。