Ubuntu20.04交叉编译OpenCV 4.5.2, 运行在Tina Linux
-
本着尽可能快完成编译和能用则用的原则, 谈谈编译目前最新的OpenCV 4.5.2编译过程.
工具链
- Tina Linux工具链
▲ 用平头哥的工具链(riscv64-linux-x86_64-20210512)编译出来:
- 在Tina Linux能跑, 但会段错误,
- 在RVBoard debian运行报运行库版本缺失(不匹配), 替换的话, 分分钟要重新烧录系统
背景
Linux tao 5.8.0-59-generic #66~20.04.1-Ubuntu SMP Thu Jun 17 11:14:10 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux cmake: 3.16.3 工具链选用: (Tina SDK 自带) tina-d1-open/out/d1-nezha/staging_dir/toolchain/bin/riscv64-unknown-linux-gnu-gcc等... 版本: gcc version 8.1.0 (C-SKY RISCV Tools V1.8.4 B20200702) 要编译的OpenCV版本: 4.5.2
开始编译
这里先提几个tips:
- ippicv库是给Intel CPU加速用的, 哪吒表示无感. 可以窜改:opencv-4.5.2/3rdparty/ippicv/ippicv.cmake中的URI导致其下载失败, 从而跳过cmake过程的下载.(亦可断网)
- 所有与python的相关库都可跳过(本人主要涉猎C/C++)
编译的指令在此. CV目录下的cmake我可能窜改了一下, 在下文补充.
opencv-4.5.2 mkdir build-tina && cd build-tina # 能编尽编原则, 可自行删减. cmake \ -DCMAKE_C_COMPILER=riscv64-unknown-linux-gnu-gcc \ -DCMAKE_CXX_COMPILER=riscv64-unknown-linux-gnu-g++ \ -DOPENCV_FORCE_3RDPARTY_BUILD=ON \ -DBUILD_ZLIB=ON \ -DBUILD_SHARED_LIBS=ON \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=./output .. # 嗯, 是Xeon. make -j12
CMakeLists.txt的diff:
#diff tmp/opencv-4.5.2/CMakeLists.txt opencv-4.5.2/CMakeLists.txt 223,227c223,224 < OCV_OPTION(BUILD_IPP_IW "Build IPP IW from source" (NOT MINGW OR OPENCV_FORCE_3RDPARTY_BUILD) IF (X86_64 OR X86) AND NOT WINRT ) < OCV_OPTION(BUILD_ITT "Build Intel ITT from source" < (NOT MINGW OR OPENCV_FORCE_3RDPARTY_BUILD) < IF (X86_64 OR X86 OR ARM OR AARCH64 OR PPC64 OR PPC64LE) AND NOT WINRT AND NOT APPLE_FRAMEWORK < ) --- > OCV_OPTION(BUILD_IPP_IW "Build IPP IW from source" ON) > OCV_OPTION(BUILD_ITT "Build Intel ITT from source" OFF) 416c413 < OCV_OPTION(WITH_ITT "Include Intel ITT support" ON --- > OCV_OPTION(WITH_ITT "Include Intel ITT support" OFF 614c611 < include(cmake/OpenCVDetectPython.cmake) --- > # include(cmake/OpenCVDetectPython.cmake) 731a729,730 > set(PYTHON_DEFAULT_AVAILABLE 0) > set(ENABLE_PYLINT 0) 1454a1454,1456 > set(WITH_IPP 0) > set(HAVE_IPP 0) > set(HAVE_IPP_IW 0) 1608a1611,1612 > set(BUILD_opencv_python2 0) > set(BUILD_opencv_python3 0)
完整的CMakeLists.txt.bmp如下图:
base64 -d CMakeLists.txt.bmp > CMakeLists.txt
![0_1626758920883_CMakeLists.txt.bmp](正在上传 100%)
-
不皮了. 补充一点:
- Tina Linux中运行test会遇到libatomic.so库缺失.
应从SDK目录中复制到板子上:
# -d 是复制快捷方式. *号会把实体也一起复制. cp -d tina-d1-open/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702/riscv64-unknown-linux-gnu/lib64/lp64d/libatomic.so* (target_path)
- diff如何应用?
- 百度一下: linux patch用法
- Tina Linux中运行test会遇到libatomic.so库缺失.
Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号