1. 安装ARM架构下的编译器

apt-cache search aarch64

sudo apt-get install g++-aarch64-linux-gnu
sudo apt-get install gcc-aarch64-linux-gnu

在终端输入以下指令查看编译器版本

aarch64-linux-gnu-g++ -v
aarch64-linux-gnu-gcc -v

2. 路径opencv3.4.16/platforms/linux下aarch64-gnu.toolchain.cmake文件修改如下:

set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(GCC_COMPILER_VERSION "" CACHE STRING "GCC Compiler version")
set(CMAKE_C_COMPILER /home/chang/InstallPackage/aarch64-linux-gnu/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /home/chang/InstallPackage/aarch64-linux-gnu/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++)
set(GNU_MACHINE "aarch64-linux-gnu" CACHE STRING "GNU compiler triple")
include("${CMAKE_CURRENT_LIST_DIR}/arm.toolchain.cmake")

3. 在opencv3.4.16下创建文件夹build和aarch64_install,进入build目录下,在终端执行编译指令

sudo cmake -DCMAKE_MAKE_PROGRAM:PATH=/usr/bin/make -DCMAKE_INSTALL_PREFIX=../aarch64_install -DWITH_CUDA=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake -DCUDA_GENERATION=Kepler ..

-DCMAKE_INSTALL_PREFIX 指定编译文件make install后保存的路径。

sudo make -j4 # 编译

make install # 文件保存到aarch64_install目录下

4. arm架构中工程cmake交叉编译指令

cmake -DCMAKE_C_COMPILER=aarch64-linux-gnu-gcc -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_BUILD_PLAT=aarch64 -DCMAKE_BUILD_TYPE=Debug ..

5. 将aarch64_install文件夹中include和bin文件夹下的文件分别拷贝到arm中的/usr/include和/usr/bin目录,然后执行ldconfig指令

Logo

更多推荐