在ubuntu14.04 LTS 上交叉编译ARM平台RK3326上运行的opencv2.4.9

PC系统:ubuntu14.04 LTS
交叉编译工具链:gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu

step1:

在opencv源代码目录创建文件夹:build,用于存放编译中间文件。

step2:

打开命令控制台,输入cmake-gui运行

step3:

配置源文件路径和编译中间文件路径:
在这里插入图片描述

step4:

在这里插入图片描述

step5:

C编译器:/usr/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc
C++编译器:/usr/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
头文件:/usr/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/aarch64-linux-gnu/libc/usr/include
在这里插入图片描述

step6:

在这里插入图片描述

step7:

取消选项:with-cuda,with-opencl
在这里插入图片描述

step8

更改安装目录:
在这里插入图片描述

step9

generate:
在这里插入图片描述

step10

打开命令控制台进入build目录,执行make -j4进行编译,当然会产生错误,后面根据错误具体再修改。

Linking CXX shared library ../../lib/libopencv_highgui.so
/usr/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/../../../../aarch64-linux-gnu/bin/ld: ../../3rdparty/lib/libIlmImf.a(ImfHeader.cpp.obj): relocation R_AARCH64_ADR_PREL_PG_HI21 against external symbol `_ZTVNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEE@@GLIBCXX_3.4.21' can not be used when making a shared object; recompile with -fPIC
/usr/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/../../../../aarch64-linux-gnu/bin/ld: ../../3rdparty/lib/libIlmImf.a(ImfHeader.cpp.obj)(.text._ZNK3Imf6Header7writeToERNS_7OStreamEb+0x368): 无法解决 R_AARCH64_ADR_PREL_PG_HI21 重定向于符号 “_ZTVNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEE@@GLIBCXX_3.4.21” 有冲突
/usr/gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/6.3.1/../../../../aarch64-linux-gnu/bin/ld: 最终连接失败: 错误的值
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libopencv_highgui.so] 错误 1
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] 错误 2
make: *** [all] 错误 2

解决办法:
修改编译目录build下面的CMakeCache.txt文件,如下所示两个地方添加 -fPIC 选项。

CMAKE_CXX_FLAGS:STRING=-fPIC
CMAKE_C_FLAGS:STRING=-fPIC

step10

再次编译,继续出错。

Linking CXX executable ../../bin/opencv_test_core
../../lib/libopencv_ts.a(ts_gtest.cpp.obj):在函数‘testing::internal::UnitTestImpl::SetTestPartResultReporterForCurrentThread(testing::TestPartResultReporterInterface*)’中:
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImpl41SetTestPartResultReporterForCurrentThreadEPNS_31TestPartResultReporterInterfaceE+0x18):对‘pthread_getspecific’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImpl41SetTestPartResultReporterForCurrentThreadEPNS_31TestPartResultReporterInterfaceE+0x108):对‘pthread_setspecific’未定义的引用
../../lib/libopencv_ts.a(ts_gtest.cpp.obj):在函数‘testing::internal::UnitTestImpl::GetTestPartResultReporterForCurrentThread()’中:
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImpl41GetTestPartResultReporterForCurrentThreadEv+0x14):对‘pthread_getspecific’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImpl41GetTestPartResultReporterForCurrentThreadEv+0x108):对‘pthread_setspecific’未定义的引用
../../lib/libopencv_ts.a(ts_gtest.cpp.obj):在函数‘testing::internal::UnitTestImpl::~UnitTestImpl()’中:
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplD2Ev+0xec):对‘pthread_getspecific’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplD2Ev+0x104):对‘pthread_key_delete’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplD2Ev+0x268):对‘pthread_getspecific’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplD2Ev+0x280):对‘pthread_key_delete’未定义的引用
../../lib/libopencv_ts.a(ts_gtest.cpp.obj):在函数‘testing::internal::ThreadLocal<testing::TestPartResultReporterInterface*>::~ThreadLocal()’中:
ts_gtest.cpp:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x10):对‘pthread_getspecific’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED2Ev[_ZN7testing8internal11ThreadLocalIPNS_31TestPartResultReporterInterfaceEED5Ev]+0x28):对‘pthread_key_delete’未定义的引用
../../lib/libopencv_ts.a(ts_gtest.cpp.obj):在函数‘testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::~ThreadLocal()’中:
ts_gtest.cpp:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED2Ev[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED5Ev]+0x14):对‘pthread_getspecific’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED2Ev[_ZN7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEED5Ev]+0x2c):对‘pthread_key_delete’未定义的引用
../../lib/libopencv_ts.a(ts_gtest.cpp.obj):在函数‘testing::internal::UnitTestImpl::UnitTestImpl(testing::UnitTest*)’中:
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplC2EPNS_8UnitTestE+0x90):对‘pthread_key_create’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplC2EPNS_8UnitTestE+0x138):对‘pthread_key_create’未定义的引用
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplC2EPNS_8UnitTestE+0x20c):对‘pthread_key_create’未定义的引用
../../lib/libopencv_ts.a(ts_gtest.cpp.obj):在函数‘testing::internal::ThreadLocal<std::vector<testing::internal::TraceInfo, std::allocator<testing::internal::TraceInfo> > >::GetOrCreateValue() const’中:
ts_gtest.cpp:(.text._ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv]+0x1c):对‘pthread_getspecific’未定义的引用
ts_gtest.cpp:(.text._ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv[_ZNK7testing8internal11ThreadLocalISt6vectorINS0_9TraceInfoESaIS3_EEE16GetOrCreateValueEv]+0x114):对‘pthread_setspecific’未定义的引用
../../lib/libopencv_core.so:对‘pthread_spin_init’未定义的引用
../../lib/libopencv_core.so:对‘pthread_spin_unlock’未定义的引用
../../lib/libopencv_core.so:对‘pthread_spin_lock’未定义的引用
../../lib/libopencv_core.so:对‘pthread_spin_destroy’未定义的引用
../../lib/libopencv_core.so:对‘pthread_once’未定义的引用
../../lib/libopencv_core.so:对‘pthread_spin_trylock’未定义的引用
collect2: error: ld returned 1 exit status
make[2]: *** [bin/opencv_test_core] 错误 1
make[1]: *** [modules/core/CMakeFiles/opencv_test_core.dir/all] 错误 2
make: *** [all] 错误 2

step11

从错误可以看出跟pthread有关, 修改build/CMakeCache.txt

CMAKE_EXE_LINKER_FLAGS:STRING=-lpthread -lrt -ldl

step12

继续编译出现如下错误:

Linking CXX executable ../../bin/opencv_test_nonfree
[ 98%] Built target opencv_test_nonfree
[ 98%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/autocalib.cpp.obj
[ 98%] Building CXX object modules/gpu/CMakeFiles/opencv_perf_gpu.dir/perf/perf_imgproc.cpp.obj
[ 98%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/exposure_compensate.cpp.obj
[ 98%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/warpers.cpp.obj
[ 98%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/fuzzymeanshifttracker.cpp.obj
[ 98%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/selfsimilarity.cpp.obj
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/detection_based_tracker.cpp.obj
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/octree.cpp.obj
[ 99%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/stitcher.cpp.obj
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/colortracker.cpp.obj
[ 99%] Building CXX object modules/stitching/CMakeFiles/opencv_stitching.dir/src/motion_estimators.cpp.obj
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/parvoretinafilter.cpp.obj
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/logpolar_bsm.cpp.obj
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/basicretinafilter.cpp.obj
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/chamfermatching.cpp.obj
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp: In member function ‘void cv::ChamferMatcher::Matching::computeDistanceTransform(cv::Mat&, cv::Mat&, cv::Mat&, float, float, float)’:
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:969:30: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
             if (&annotate_img!=NULL) {
                              ^
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:1016:34: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
                 if (&annotate_img!=NULL) {
                                  ^
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp: In member function ‘cv::ChamferMatcher::Match* cv::ChamferMatcher::Matching::localChamferDistance(cv::Point, cv::Mat&, cv::Mat&, cv::ChamferMatcher::Template*, float)’:
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:1111:25: error: the compiler can assume that the address of ‘orientation_img’ will never be NULL [-Werror=address]
     if (&orientation_img!=NULL) {
                         ^
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/magnoretinafilter.cpp.obj
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:1111:5: warning: nonnull argument ‘orientation_img’ compared to NULL [-Wnonnull-compare]
     if (&orientation_img!=NULL) {
     ^~
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp: In member function ‘void cv::ChamferMatcher::Matching::computeDistanceTransform(cv::Mat&, cv::Mat&, cv::Mat&, float, float, float)’:
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:1016:17: warning: nonnull argument ‘annotate_img’ compared to NULL [-Wnonnull-compare]
                 if (&annotate_img!=NULL) {
                 ^~
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/chamfermatching.cpp:969:13: warning: nonnull argument ‘annotate_img’ compared to NULL [-Wnonnull-compare]
             if (&annotate_img!=NULL) {
             ^~
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/retinafilter.cpp.obj
[ 99%] Building CXX object modules/contrib/CMakeFiles/opencv_contrib.dir/src/rgbdodometry.cpp.obj
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/rgbdodometry.cpp:65:47: fatal error: unsupported/Eigen/MatrixFunctions: 没有那个文件或目录
 #  include <unsupported/Eigen/MatrixFunctions>
                                               ^
compilation terminated.
make[2]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/src/rgbdodometry.cpp.obj] 错误 1
make[2]: *** 正在等待未完成的任务....
Linking CXX shared library ../../lib/libopencv_stitching.so
[ 99%] Built target opencv_stitching
Scanning dependencies of target opencv_perf_stitching
Scanning dependencies of target opencv_test_stitching
[ 99%] [ 99%] [ 99%] Building CXX object modules/stitching/CMakeFiles/opencv_test_stitching.dir/test/test_blenders.cpp.obj
Building CXX object modules/stitching/CMakeFiles/opencv_test_stitching.dir/test/test_main.cpp.obj
Building CXX object modules/stitching/CMakeFiles/opencv_perf_stitching.dir/perf/perf_stich.cpp.obj
In file included from /home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/flann/include/opencv2/flann/params.h:33:0,
                 from /home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/flann/include/opencv2/flann/flann_base.hpp:41,
                 from /home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/flann/include/opencv2/flann/flann.hpp:50,
                 from /home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/stitching/perf/perf_stich.cpp:4:
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/flann/include/opencv2/flann/any.h: In member function ‘virtual void cvflann::anyimpl::big_any_policy<T>::static_delete(void**)’:
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/flann/include/opencv2/flann/any.h:83:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
         if (* x) delete (* reinterpret_cast<T**>(x)); *x = NULL;
         ^~
/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/flann/include/opencv2/flann/any.h:83:55: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
         if (* x) delete (* reinterpret_cast<T**>(x)); *x = NULL;
                                                       ^
cc1plus: some warnings being treated as errors
make[2]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/src/chamfermatching.cpp.obj] 错误 1
make[1]: *** [modules/contrib/CMakeFiles/opencv_contrib.dir/all] 错误 2
make[1]: *** 正在等待未完成的任务....
[ 99%] Building CXX object modules/stitching/CMakeFiles/opencv_pe

以下错误解决办法:
修改build/modules/contrib/CMakeFiles/opencv_contrib.dir/flags.make
删除 CXX_FLAGS 中的 -Werror=address

2.4.9/modules/contrib/src/chamfermatching.cpp:969:30: error: the compiler can assume that the address of ‘annotate_img’ will never be NULL [-Werror=address]
             if (&annotate_img!=NULL) {

以下错误解决办法:
进入Eigen3库目录发现缺少unsupported目录,下载新的Eigen库并替换,因为Eigen库全部都是头文件,所以直接替换就好,不依赖具体的平台。

/home/rootroot/workspace/BAOLE_CLEAN_ROBOT/BL505/CORE-BOARD-PRO/WITHSRC/RK3326/lib/opencv-2.4.9/modules/contrib/src/rgbdodometry.cpp:65:47: fatal error: unsupported/Eigen/MatrixFunctions: 没有那个文件或目录

step13

再次编译,编译成功。

step14

执行 make install 进行安装,安装完成后,可以将Install目录下的内容拷贝到RK3326板子上/usr目录下相关的目录中即可。

参考:
https://blog.csdn.net/lucifer615/article/details/50350751
https://blog.csdn.net/jacke121/article/details/56038046
https://blog.csdn.net/newnewman80/article/details/100017179

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu 14.04 LTS是一个长期支持版本的Linux操作系统,下面是其安装教程: 1. 下载镜像:首先,在Ubuntu官方网站上下载Ubuntu 14.04 LTS的镜像文件。你可以选择64位或32位版本,取决于你的计算机架构。 2. 创建安装介质:下载完成后,你需要将镜像文件写入USB闪存驱动器或光盘中,以用作安装介质。你可以使用Rufus、Unetbootin或Etcher等工具来完成这个任务。确保将该设备设置为启动设备。 3. 启动安装介质:将USB闪存驱动器或光盘插入计算机,并重新启动计算机。进入计算机的BIOS设置,并将启动顺序更改为首先从USB闪存驱动器或光盘启动。 4. 开始安装:计算机启动后,将显示Ubuntu的安装界面。选择“Install Ubuntu”来启动安装过程。 5. 选择语言:选择你想要在Ubuntu中使用的语言。 6. 检查系统要求:系统会检查你的计算机是否满足安装Ubuntu所需的最低硬件要求。确保在继续安装之前你的计算机满足这些要求。 7. 选择安装类型:选择你想要执行的安装类型。你可以选择完全擦除硬盘并安装Ubuntu,或者将其安装在另一个操作系统旁边以实现双引导。 8. 设置磁盘分区:如果你选择将Ubuntu安装在另一个操作系统旁边,你需要设置磁盘分区。在这一步中,你可以选择自动将其分区,或者手动设置分区。 9. 设置用户信息:输入你的用户名和计算机名称,并设置密码。 10. 等待安装完成:一旦完成上述步骤,点击“Install”按钮以开始Ubuntu的安装过程。安装过程可能需要一些时间,取决于你的计算机性能。 11. 重启计算机:一旦安装完成,你将收到一个通知要求你重启计算机。 12. 登录Ubuntu:重新启动计算机后,你将看到登录界面。输入你在安装过程中设置的密码,并登录到Ubuntu 14.04 LTS操作系统中。 这就是Ubuntu 14.04 LTS的安装步骤。祝你安装成功并享受使用Ubuntu的乐趣!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值