赞
踩
使用的交叉编译器为aarch64-linux-gnu-g++,在ubuntu中可以直接进行安装,如果在嵌入式端侧使用的是32位系统的,则安装
sudo apt install aarch64-linux-gnu-g++
安装完成之后使用aarch64-linux-gnu-g++ -v可以查看对应的版本
Using built-in specs.
COLLECT_GCC=aarch64-linux-gnu-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/aarch64-linux-gnu/11/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.3.0-1ubuntu1~22.04.1' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --without-target-system-zlib --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=aarch64-linux-gnu --program-prefix=aarch64-linux-gnu- --includedir=/usr/aarch64-linux-gnu/include --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.3.0 (Ubuntu 11.3.0-1ubuntu1~22.04.1)
从上图可以看出gcc的版本为11.3,但是我在嵌入式端侧使用的gcc版本为ggc 8.2,为了避免了一些不必要的问题,所以在交叉编译器中应该使用gcc8.2
相关的版本可以从arm_developer和linaro进行下载,arm_developer的版本较新,linaro版本较老,gcc8.2相对来说比较老,所以在linaro下载的
得到相应的安装包后,并将其进行解压,解压后在bin文件夹下可以找到相应的工具aarch64-linux-gnu-gcc和aarch64-linux-gnu-g++
jing@jing:/usr/bin/gcc-arm-8.2-2018.08-x86_64-aarch64-linux-gnu/bin$ ls
aarch64-linux-gnu-addr2line aarch64-linux-gnu-gcov-tool
aarch64-linux-gnu-ar aarch64-linux-gnu-gdb
aarch64-linux-gnu-as aarch64-linux-gnu-gfortran
aarch64-linux-gnu-c++ aarch64-linux-gnu-gprof
aarch64-linux-gnu-c++filt aarch64-linux-gnu-ld
aarch64-linux-gnu-cpp aarch64-linux-gnu-ld.bfd
aarch64-linux-gnu-elfedit aarch64-linux-gnu-nm
aarch64-linux-gnu-g++ aarch64-linux-gnu-objcopy
aarch64-linux-gnu-gcc aarch64-linux-gnu-objdump
aarch64-linux-gnu-gcc-8.2.1 aarch64-linux-gnu-ranlib
aarch64-linux-gnu-gcc-ar aarch64-linux-gnu-readelf
aarch64-linux-gnu-gcc-nm aarch64-linux-gnu-size
aarch64-linux-gnu-gcc-ranlib aarch64-linux-gnu-strings
aarch64-linux-gnu-gcov aarch64-linux-gnu-strip
aarch64-linux-gnu-gcov-dump
至此,交叉编译器的配置工作完成,后续可以在cmake中指定相应的版本
本次使用的OpenCV版本为4.7
解压相应的压缩包后,相应的cmake配置文件在/platforms/linux路径下,根据嵌入式端侧的不同,选择相应的配置工具,我选择的为aarch64-gnu.toolchain.cmake,修改相应的内容,修改后如下
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(GCC_COMPILER_VERSION "" CACHE STRING "GCC Compiler version")
SET (CMAKE_C_COMPILER "/usr/bin/gcc-arm-8.2-2018.08-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc")
SET (CMAKE_CXX_COMPILER "/usr/bin/gcc-arm-8.2-2018.08-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")
SET (CMAKE_C_COMPILER “/usr/bin/gcc-arm-8.2-2018.08-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc”)
SET (CMAKE_CXX_COMPILER “/usr/bin/gcc-arm-8.2-2018.08-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-g++”)
就是上面交叉编译器配置所解压后的gcc8.2的位置
开始进行交叉编译,在opencv4.7的目录下新建build,并进入,然后执行以下命令
sudo cmake -DCMAKE_MAKE_PROGRAM:PATH=/usr/bin/make -DWITH_CUDA=OFF -DENABLE_PRECOMPILED_HEADERS=OFF -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake -DCUDA_GENERATION=Kepler -DWITH_GTK=ON ..
运行的结果如下所示,可见版本已为8.2.1
-- 'Release' build type is used by default. Use CMAKE_BUILD_TYPE to specify build type (Release or Debug)
-- The CXX compiler identification is GNU 8.2.1
-- The C compiler identification is GNU 8.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/gcc-arm-8.2-2018.08-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/gcc-arm-8.2-2018.08-x86_64-aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- ocv_init_download: OpenCV source tree is not fetched as git repository. 3rdparty resources will be downloaded from github.com by default.
-- Detected processor: aarch64
...
在当前文件夹下执行make -j16 ,j后面的数字需要根据cpu的线程来确定
至此交叉编译完成
在build文件夹下make install DESTDIR=./g8.2install,即安装到当前目录下的g8.2install目录下,其目录文件如下
.
├── bin
├── include
├── lib
└── share
将lib和include目录分别拷贝到板子的/usr/lib和/usr/include目录下
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。