转http://blog.163.com/yankang0612@126/blog/static/16418746420114190365981/?latestBlog
平台是TQ2440开发板,编译器版本时4.3.3。首先下载opencv2.2.0源码和cmake-gui工具,解压到/usr/local目录下,在/usr/local目录下建opencv-arm文件夹,同时建一个目录arm用来放置最终生成的文件,
在终端运行cmake-gui 选择源代码目录:/usr/local/OpenCV-2.2.0
选择Build目录:/usr/local/opencv-arm/
点击Configure,保持generator为Unix Makefiles,选择Specify options for cross-compiling,点击Next
Operating System填写arm-inux
C Compilers填写/opt/EmbedSky/4.3.3/bin/arm-linux-gcc
C++ Compilers填写/opt/EmbedSky/4.3.3/bin/arm-linux-g++
程序库的Target Root填写/opt/EmbedSky/4.3.3/,然后点击Finish
修改默认配置,默认安装目录为/usr/local,为便于查找生成的库文件,把CMAKE_INSTALL_PREFIX变量改为/usr/local/arm ,点击Generate生成Makefile 然后make,
到59%的时候出错,/usr/local/OpenCV-2.2.0/modules/highgui/src/grfmt_png.cpp:55:24: error: libpng/png.h: No such file or directory
结果在OpenCV-2.2.0/3rdparty/libpng/下找到了png.h,在png.cpp下补全路径,错误消失。继续make。
在79%出错,OpenCV-2.2.0/modules/ml/src/gbt.cpp:474: error: 'expl' was not declared in this scope;修改gdb.cpp,注释掉#if android 和#endlf,继续。
在81%时出错,http://www.cnblogs.com/lib/libopencv_haartraining_engine.a(cvhaartraining.obj): In function `cvCreateTestSamples(char const*, char const*, int, int, char const*, int, int, int, double, double, double, int, int, int)':
cvhaartraining.cpp:(.text._Z19cvCreateTestSamplesPKcS0_iiS0_iiidddiii+0x454): undefined reference to `cvShowImage'
cvhaartraining.cpp:(.text._Z19cvCreateTestSamplesPKcS0_iiS0_iiidddiii+0x45c): undefined reference to `cvWaitKey'
cvhaartraining.cpp:(.text._Z19cvCreateTestSamplesPKcS0_iiS0_iiidddiii+0x534): undefined reference to `cvNamedWindow'
http://www.cnblogs.com/lib/libopencv_haartraining_engine.a(cvhaartraining.obj): In function `cvCreateTrainingSamples(char const*, char const*, int, int, char const*, int, int, int, double, double, double, int, int, int)':
找了好长时间问题,还是没有答案,希望那位知道怎么改的能告诉我,
我重新在/opt目录下按照上述步骤解压,make之后,顺利到达79%,改完之后在81%出现http://www.cnblogs.com/lib/libcxcore.so: undefined reference to `clock_gettime'
解决方法:修改CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread -lrt,重新编译,错误消除 。接着96%时。
出现错误,http://www.cnblogs.com/lib/libopencv_features2d.so: undefined reference to `cv::SIFT::SIFT(double, bool, bool, int, int, int, int)'
解决方法:在/opt/OpenCV2.2.0/modules/features2d/src/sift.cpp下 #ifdef __arm__
#define ARM_NO_SIFT
#endif 注释掉#define ARM_NO_SIFT.错误消除,
好了,安全到达100%。
所以大家最好时把要建的opencv-arm和最终生成opencv的arm目录和交叉编译器放在同一个目录下。至于为什么,我也想不明白阿。
之后make install
把生成的opencv头文件和库文件复制到交叉编译器中:首先复制/opt/arm/include/opencv/下opencv2目录和opencv下的.h文件到/opt/EmbedSky/4.3.3/arm-none-linux-gnueabi/include目录下。然后复制/opt/arm/lib下的库文件到/EmbedSky/4.3.3/arm-none-linux-gnueabi/libc/lib下。
测试下arm-linux-g++ -lcv -lcxcore -lhighgui -lpthread -lrt -o test test.c
生成二进制文件。
最后复制/opt/arm/lib下的库文件到开发板的/lib/目录下。复制test执行文件,如果正常执行,则说明我们的移植成功了。