参考文档
- NCNN在RK3288 Linux系统的原生编译问题解决
本文档涉及到的目标硬件为英伟达JetsonTX1(4核Cortex-A53,Armv8.0架构),但是对其他Arm芯片也有一定的借鉴意义,只需要更换交叉编译链即可。
开发环境介绍
- 主机操作系统:Ubuntu14.04 64位
- 目标平台:JetsonTX1 TegraX1
- 交叉工具链:aarch64-unknown-linux-gnu,gcc4.9.2
设置交叉编译链
export ARCH=arm
export PATH=/opt/toolchain/aarch64-unknown-linux-gnu/bin/:$PATH
export CROSS_COMPILE=aarch64-unknown-linux-gnu-
export CC=/opt/toolchain/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-gcc
export CXX=/opt/toolchain/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-g++
export LD=/opt/toolchain/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-ld
export AR=/opt/toolchain/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-ar
export AS=/opt/toolchain/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-as
export RANLIB=/opt/toolchain/aarch64-unknown-linux-gnu/bin/aarch64-unknown-linux-gnu-ranlib
echo $CC
下载依赖库
依赖库 |
版本 |
下载地址 |
opencv
3.2.0
https://github.com/opencv/opencv
protobuf
3.2.0
https://github.com/google/protobuf
编译Opencv
新建cmake Build目录
cd opencv-3.2.0
mkdir _install
使用cmake-gui进行配置
选择Specify options for cross-compiling,进入交叉编译链设置界面
点击Configure生成配置选项,并且打开Advancd选项
修改设置选项:
BUILD_SHARED_LIBS
CMAKE_BUILD_TYPE
CMAKE_CXX_FLAGS
CMAKE_C_FLAGS
CMAKE_EXE_LINKER_FLAGS
CMAKE_INSTALL_PREFIX
WITH_CUDA
WITH_CUFFT
WITH_EIGEN
WITH_FFMPEG
WITH_OPENCL
WITH_OPENCLAMDBLAS
WITH_OPENCLAMDFFT
WITH_OPENCL_SVM
WITH_TIFF
WITH_1394
WITH_GSTREAMER
WITH_JASPER
WITH_LAPACK
WITH_MATLAB
WITH_WEBP
点击Generate生成Makefile
进入_install目录&编译
cd _install
make -j8
make install
编译Protobuf
安装软件
sudo apt-get install curl libtool
生成PC版本protoc可执行文件,供编译ARM版本库时使用
cd protobuf-3.2.0
./autoconf.sh
./configure --prefix=/usr/local/PC/protobuf-3.2.0
编译ARM版本
cd protobuf-3.2.0
./autoconf.sh
./configure --build=i686-pc-linux --host=arm-linux
--with-protoc=/usr/local/PC/protobuf-3.2.0/bin/protoc
--prefix=/usr/local/TegraX1/protobuf-3.2.0 CFLAGS="-fPIC" CXXFLAGS="-fPIC -DNDEBUG"
编译&安装
make -j8
make install
编译NCNN
修改CmakeLists.txt
此处的修改只适用于Armv7的设备,Armv8设备已经默认开启neon指令,所以不需要额外指定
添加行
add_definitions("-mfpu=neon")
修改src/CmakeLists.txt
if((ANDROID AND ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a"))
修改为
if(TRUE OR (ANDROID AND ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a"))
这里会强制进入ARM平台编译,否则会编译成X86的版本在测试时会出现计算性能非常低的问题
新建cmake Build目录
cd ncnn-20171225
mkdir _install
打开cmake-gui进行交叉编译链配置,参考编译Opencv时的操作
点击Configure生成配置选项,并且打开Advancd选项
如果Cmake找不到Protobuf的位置会报错,暂时先不用管,后面修改设置后错误会消失
修改设置选项:
CMAKE_BUILD_TYPE
CMAKE_INSTALL_PREFIX
PROTOBUF_INCLUDE_DIR /usr/local/TegraX1/protobuf-3.2.0/include
PROTOBUF_LIBRARY /usr/local/TegraX1/protobuf-3.2.0/lib/libprotobuf.a
PROTOBUF_LITE_LIBRARY /usr/local/TegraX1/protobuf-3.2.0/lib/libprotobuf-lite.so
PROTOBUF_PROTOC_EXECUTABLE /usr/local/PC/protobuf-3.2.0/bin/protoc
点击Generate生成Makefile
进入_install目录&编译
cd _install
make -j8
make install