arm平台Opencv静态和动态库的编译

1 准备工作

(1)VMware安装以及相关问题
(2)cmake-gui安装

在Ubuntu16.04 下安装cmake-gui
1)安装gui:sudo apt-get install cmake-qt-gui
2)运行:cmake-gui
参考:https://blog.csdn.net/u012785169/article/details/112553100

(3)Linux的gcc和g++的区别
(4)gcc和arm-linux-gcc的区别
(5)soc通俗理解:

soc≈一台电脑的主机,而不是=cpu,soc≈一台电脑的主机,而不是=cpu;
SoC的全称叫做:System-on-a-Chip,中文的的意思就是“把系统都做在一个芯片上”,如果在PC时代我们说一个电脑的核心是CPU,那么在智能终端时代,手机的核心就是这个SoC。

这么说是因为SoC上集成了很多手机上最关键的部件,比如CPU、GPU、内存、也就说虽然它在主板上的存在是一个芯片,但是它里边可是由很多部件封装组成的。
参考:https://www.jianshu.com/p/ab99d835b55a

2 arm平台Opencv静态和动态库的编译

2.1 参考文档:https://blog.csdn.net/u013816798/article/details/52868817

2.2 注意

(1)生成动态库还是静态库取决于在上述参考文档“第三步”中configure是勾选BUILD_SHARED_LIBS,则生成动态库;否则,不勾选则生成静态库。
(2)不同芯片会有不同的arm-linux-gcc和arm-linux-g++,在上述参考文档“第二步”中configure编译器路径填具体芯片的。
(3)第二步中,target root路径与编译器路径bin根目录相同。
(4)第四步中,CMAKE_INSTALL_PREFIX安装位置为最后编译生成的库的位置,.a/.so和include

windows: .exe + .lib/.dll(静态库 / 动态库)
linux: .exe + .a/.so(静态库 / 动态库),调用只能在arm芯片端

2.3 报错解决

(1)报错1:

../../lib/libopencv_ts.a(ts_gtest.cpp.obj): In function `testing::internal::UnitTestImpl::~UnitTestImpl()':
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplD1Ev+0xa4): undefined reference to `pthread_getspecific'
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplD1Ev+0xc0): undefined reference to `pthread_key_delete'
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplD1Ev+0x22c): undefined reference to `pthread_getspecific'
ts_gtest.cpp:(.text._ZN7testing8internal12UnitTestImplD1Ev+0x248): undefined reference to `pthread_key_delete'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_init'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_unlock'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_lock'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_destroy'
../../lib/libopencv_core.so: undefined reference to `pthread_once'
../../lib/libopencv_core.so: undefined reference to `clock_gettime'
../../lib/libopencv_core.so: undefined reference to `pthread_spin_trylock'
collect2: ld returned 1 exit status
modules/core/CMakeFiles/opencv_test_core.dir/build.make:387: recipe for target 'bin/opencv_test_core' failed
make[2]: *** [bin/opencv_test_core] Error 1
CMakeFiles/Makefile2:1437: recipe for target 'modules/core/CMakeFiles/opencv_test_core.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

解决: configure配置中取消BUILD_TESTS

(2)报错2:

fatal error:Killed signal terminated program cc1plus

解决: 虚拟机分配的内存小了,扩大分配的内存

(3)报错3:

thread_utils.c:(.text.Reset+0xe0): undefined reference to 'pthread_create'
thread_utils.c:(.text.End+0x3c): undefined reference to 'pthread_join'

解决: CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空, 现在加上-lpthread -lrt -ldl,

(4)报错4: make过程中,针对常见报错,可以取消WITH_TIFF, WITH_JPEG, WITH_PNG, BUILD_TESTS, BUILD_PERF_TESTS

(5)报错5:

opencv-3.4.6/3rdparty/protobuf/src/google/protobuf/stubs/common.cc:52:2: error: #error "No suitable threading library available."
3rdparty/protobuf/CMakeFiles/libprotobuf.dir/build.make:350: recipe for target '3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/common.cc.obj' failed
make[2]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/common.cc.obj] Error 1
CMakeFiles/Makefile2:642: recipe for target '3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all' failed
make[1]: *** [3rdparty/protobuf/CMakeFiles/libprotobuf.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

解决:
opencv-3.4.6/3rdparty/protobuf/src/google/protobuf/stubs/common.cc文件,发现是找不到HAVE_PTHREAD宏定义导致找不到pthread库,本文解决办法就是在该文件加上该句宏定义(临时解决,有其他更好的方法欢迎告知探讨)#define HAVE_PTHREAD

参考:http://www.huangea.com/2018/03/08/962/

3 补充

arm-linux-gcc交叉编译器安装

参考:https://www.cnblogs.com/tansuoxinweilai/p/11602830.html 全局?

猜你喜欢

转载自blog.csdn.net/weixin_41874898/article/details/113860733
今日推荐