交叉編譯並移植opencv3.0.0到arm板

原文地址:http://blog.csdn.net/gatieme/article/details/49080355


項目需求,交叉編譯opencv,並移植到arm中。

在opencv2.0以上的版本編譯都要藉助於cmake工具生成Makefile 
2.0一下版本纔是使用configure生成Makefile 
請確保宿主機已經安裝cmake和cmake-gui工具,如果請自行安裝

sudo apt-get install cmake cmake-qt-gui  cmake-curses-gui
  • 1
  • 1

開發環境 
開宿主機:Fedora9.0 
交叉編譯器:友善之臂arm-linux-gcc4.4.3 
自動化編譯工具: cmake version 2.8.12.2

編譯


下載opencv源代碼

項目官網:http://opencv.org/ 
下載地址:http://opencv.org/downloads.html 
這裏寫圖片描述 
源碼我放置在自己目錄的/opencv/opev3.0.0-src 下 
期望的構建目錄在/opencv/opencv3-build 下 
期望的安裝目錄是/opt/arm/opencv/opencv3-arm

cmake配置生成makefile


運行cmake的圖形化工具cmake-gui

sudo cmake-gui
  • 1
  • 1

這裏寫圖片描述 
選擇源代碼目錄/opencv/opev3.0.0-src 
選擇Build目錄/opencv/opencv3-build,大家根據自己設置配置編譯目錄

點擊Configure或者Generator 
選擇Unix Makefiles, 
接着選擇Specify options for cross-compiling,

1. 列表內容 
點擊Next,接着開始配置交叉編譯環境的信息

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

make編譯並且安裝

sudo make
sudo make install 
  • 1
  • 2
  • 1
  • 2

出現問題


我們剛纔的配置其實肯定是有問題的,因爲一堆依賴庫沒有配置鏈接參數,但是我們又不知道需要哪些庫,所以我們只能等待出現問題進行解決。

pthread


報錯

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'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

很明顯是pthread的庫,

解決

修改/opt/opencv3-build目錄下的CMakeCache.txt 
CMAKE_EXE_LINKER_FLAGS原來爲空,加上-lpthread -lrt

dlfcn


問題

undefined reference to `dlerror'
undefined reference to `dlopen'
  • 1
  • 2
  • 1
  • 2

解決

CMAKE_EXE_LINKER_FLAGS繼續加上-ldl

parallel_pthreads_set_threads_num

問題

undefined reference to `dlerror'
undefined reference to `dlopen'
  • 1
  • 2
  • 1
  • 2
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)'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

解決

這個是編譯工具鏈的問題,解決了快一天 
後來重要找到了解決方案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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章