瑞芯微Rockchip开发者社区
直播中

李星童

7年用户 1022经验值
私信 关注
[问答]

在ubuntu14.04 LTS上的交叉编译工具链该怎样去实现呢

在ubuntu14.04 LTS上的交叉编译工具链该怎样去实现呢?有哪些操作步骤?

回帖(2)

范佳慧

2022-2-17 13:53:25
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进行编译,当然会产生错误,后面根据错误具体再修改。

打开命令控制台进入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::~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 > >::~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 > >::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
举报

刘桂英

2022-2-17 13:53:29
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
                                               ^
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::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(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(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/rgbdo


step13

再次编译,编译成功。
step14

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

更多回帖

发帖
×
20
完善资料,
赚取积分