项目需求,交叉编译opencv,并移植到arm中。
在opencv2.0以上的版本编译都要借助于cmake工具生成Makefile
2.0一下版本才是使用configure生成Makefile
请确保宿主机已经安装cmake和cmake-gui工具,如果请自行安装
sudo apt-get install cmake cmake-qt-gui cmake-curses-gui
开发环境
开宿主机:Fedora9.0
交叉编译器:友善之臂arm-linux-gcc4.4.3
自动化编译工具: cmake version 2.8.12.2
项目官网:http://opencv.org/
下载地址:http://opencv.org/downloads.html
源码我放置在自己目录的/opencv/opev3.0.0-src
下
期望的构建目录在/opencv/opencv3-build
下
期望的安装目录是/opt/arm/opencv/opencv3-arm
运行cmake的图形化工具cmake-gui
sudo cmake-gui
选择源代码目录/opencv/opev3.0.0-src
选择Build目录/opencv/opencv3-build
,大家根据自己设置配置编译目录
点击Configure或者Generator
选择Unix Makefiles,
接着选择Specify options for cross-compiling,
Operating System填写arm-inux
C Compilers填写您交叉编译器arm-linux-gcc命令的地址
C++ Compilers填写arm-linux-g++的地址
程序库的Target Root填写交叉编译器的bin目录,
然后点击Finish,您的配置信息就出来的
注意默认的安装路径为 修改默认配置,默认安装目录为/usr/local
但是我们交叉编译的来说并不合适,这样会替换我们宿主机上原有的库,
所以我把CMAKE_INSTALL_PREFIX
变量改为/opt/arm/opencv/opencv3-arm
好了最后点击Configure
进行配置,然后点击Gennerate
就会生成Makefile
sudo make
sudo make install
我们刚才的配置其实肯定是有问题的,因为一堆依赖库没有配置链接参数,但是我们又不知道需要哪些库,所以我们只能等待出现问题进行解决。
Linking CXX executable ../../bin/opencv_test_calib3d
../../lib/libopencv_core.so: undefined reference to `pthread_key_create' ../../lib/libopencv_core.so: undefined reference to `pthread_getspecific'
../../lib/libopencv_ts.so: undefined reference to `pthread_key_delete' ../../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_setspecific'
很明显是pthread的库,
修改/opt/opencv3-build目录下的CMakeCache.txt
CMAKE_EXE_LINKER_FLAGS
原来为空,加上-lpthread -lrt
undefined reference to `dlerror'
undefined reference to `dlopen'
CMAKE_EXE_LINKER_FLAGS
继续加上-ldl
undefined reference to `dlerror'
undefined reference to `dlopen'
Linking CXX executable ../../bin/opencv_perf_core
../../lib/libopencv_core.so: undefined reference to `parallel_pthreads_set_threads_num(int)'
../../lib/libopencv_core.so: undefined reference to `parallel_pthreads_get_threads_num()'
../../lib/libopencv_core.so: undefined reference to `parallel_for_pthreads(cv::Range const&, cv::ParallelLoopBody const&, double)'
这个是编译工具链的问题,解决了快一天
后来重要找到了解决方案Fixed compilation of pthread-based parallel_for with gcc 4.4.3
修改modules/core/src/parallel.cpp,自132行开始添加7处删除5处(+表示要添加,-表示要删除)
namespace cv
{
ParallelLoopBody::~ParallelLoopBody() {}
+#if defined HAVE_PTHREADS && HAVE_PTHREADS
+ void parallel_for_pthreads(const cv::Range& range, const cv::ParallelLoopBody& body, double nstripes);
+ size_t parallel_pthreads_get_threads_num();
+ void parallel_pthreads_set_threads_num(int num);
+#endif
}
+
namespace
{
#ifdef CV_PARALLEL_FRAMEWORK
@@ -301,7 +307,7 @@ void cv::parallel_for_(const cv::Range& range, const cv::ParallelLoopBody& body,
}
#elif defined HAVE_PTHREADS
- void parallel_for_pthreads(const Range& range, const ParallelLoopBody& body, double nstripes);
+
parallel_for_pthreads(range, body, nstripes);
#else
@@ -361,8 +367,6 @@ int cv::getNumThreads(void)
#elif defined HAVE_PTHREADS
- size_t parallel_pthreads_get_threads_num();
-
return parallel_pthreads_get_threads_num();
#else
@@ -424,8 +428,6 @@ void cv::setNumThreads( int threads )
#elif defined HAVE_PTHREADS
- void parallel_pthreads_set_threads_num(int num);
-
parallel_pthreads_set_threads_num(threads);
#endif