第一次写博客,别喷。
环境:
Ubuntu11.10 + TQ的交叉编译链4.46 + cmake-2.8.12.2-Linux-i386 + OpenCV-2.4.1
配置的我就说了,网上有很多,自己去找。主要说一些错误的解决的办法。
例如:我在 /usr/local/Opencv-2.4.1放Opencv源码,另外在 /usr/local下新建Opencv-arm目录存放交叉编译后的库
配置好后,执行cmake-gui,在弹出的窗口中的"Where is the source code"选择Opencv源码目录Opencv-2.4.1;在"Where to build the binarices"选择存放交叉编译的目录Opencv-arm,点击左下角的configure,弹出一个窗口,
框条选择“Unix Makefiles”,下面的选择最后一个;然后点击finish;然后弹出新窗口,“Operating System”填写arm-linux,“Version”填写Opencv版本(2.4.1);“C”选择交叉编译链(/opt/EmbedSky/4.4.6/bin/arm-linux-gcc);“C++”选择交叉编译链(/opt/EmbedSky/4.4.6/bin/arm-linux-g++);“Target Root”选择交叉编译链的目录(/opt/EmbedSky/4.4.6/);然后点击Finished;(重点来了)弹出的红框中去掉BUILD_OPENER、BUILD_TIFF、BUILD_ZLIB、WITH_OPENER、WITH_TIFF其他的默认就行,点击Generate,OK!若重新cmake-gui最好在弹出的框中选择File-->Delete Cache,然后重新配置。基本可以省去几个错误!!!
配置完,进入交叉编译库存放的目录(Opencv-arm)进行make,然后报错了(不一定都有)~~~
错误分析:
1,XML::Parser perl module is required for intltool错误
解决:cpan install XML::Parser
2,Linking CXX shared library ../../lib/libopencv_core.so
..................................................................
..................................................................
'a local symbol' can not be used when making a shared object;recompile with -fPIC
................................................:could not read symbols :Bad value
collect2 :ld returned 1 exit status
make[2]:***[lib/libopencv_core.so]错误1
make[1]:***[modules/core/CMakeFiles/opencv_core.dir/all]错误2
.....................................
版本问题(64位Ubuntu)
解决:
进入opencv目录下的3rdparty的对应目录CMakeFiles/ *.dir下(所有的),打开flags.make,在C_FLAGS = 后添加-O3 -fPIC,用来支持在64位机上编译
如../3rdparty/zlib/CMakeFiles/zlib.dir/flags.make
修改C_FLAGS = -W -Wall 为 C_FLAGS = -O3 -fPIC -W -Wall
和
修改CXX_FLAGS = -W -Wall 为 C_FLAGS = -O3 -fPIC -W -Wall
3,
collect2:ld returned 1 exit status
make[2]:***[lib/libopencv_highgui.so]错误1
make[1]:***[modules/highgui/CMakeFile/opencv_highgui.dir/all]错误2
..........................................
解决:
在cmake-gui的界面中把以下选项去掉
BUILD_OPENER、BUILD_TIFF
4,
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'
collect2: ld returned 1 exit status
make[2]: *** [bin/opencv_test_calib3d] Error 1
make[1]: *** [modules/calib3d/CMakeFiles/opencv_test_calib3d.dir/all] Error 2
make: *** [all] Error 2
解决( ld returned 1 exit status都可以):
修改目录下的CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread -lrt