交叉编译opencv

来源:互联网 发布:巨人网络2017利润 编辑:程序博客网 时间:2024/05/29 18:13
这两天着手移植opencv工作,但是遇到很恶心的问题,看到网上也有不少朋友遇到,于是记录下来,分享给大家。

1、当然是交叉编译xvid,网上有很多教程,我就不罗嗦啦。
2、交叉编译x264,网上资料也很丰富,我也不多说啦。
3、交叉编译ffmpeg,我用的是0.6.4的版本,网上用介绍得比较多,不过我的配置文件跟很网上的不太一样,启用了x264和xvid的支持,加入了ARMV6的支持,一个关键的地方就是下面配置中的红色部分,要指出264,和xvid库文件和头文件的路径,要不然会找不到,贴出来给大家看看

./configure --cross-prefix="/usr/local/arm/4.3.2/bin/arm-linux-" --enable-cross-compile --target-os=linux --cc=arm-linux-gcc --arch=arm --prefix=/usr/local/arm/4.3.2/ --enable-shared --disable-static --enable-gpl --enable-nonfree --enable-ffmpeg --disable-ffplay --enable-ffserver --enable-swscale --enable-pthreads --disable-yasm --disable-stripping --cpu=armv6 --enable-libx264--extra-cflags=-I/usr/local/arm/4.3.2/include --extra-ldflags=-L/usr/local/arm/4.3.2/lib--enable-libxvid --incdir=PREFIX/include/ffmpeg CXXFLAGS=-D_STDC_CONSTANT_MACROS

接下来就是opencv啦,一步一步写吧,由于不太会用cmake,网上的配置多是基于./configure方式的,所以我就是用了2.0.0的版本,,由于要做视频处理,所以必须加入ffmpeg的支持,网上很多都没具体介绍ffmpeg的支持,必须要注意,同样要指出ffmpeg的库路径和头文件路径,由于我都放在一起,也就是上面红色的地方,最开始的配置脚本如下
./configure --host=arm-linux --prefix=/usr/local/arm/4.3.2 --without-gtk --without-carbon --without-quicktime --without-1394libs--with-ffmpeg --without-python --without-swig --disable-apps --enable-shared CPPFLAGS=-I/usr/local/arm/4.3.2/include LDFLAGS=-L/usr/local/arm/4.3.2/lib

美美的等着出现 use ffmpeg yes ,结果却是可恶的NO,我也就此埋头苦干十多个小时。出现的错误如下,在终端打印出这样的信息
checking ffmpeg/avcodec.h usability... no
checking ffmpeg/avcodec.h presence... yes
configure: WARNING: ffmpeg/avcodec.h: present but cannot be compiled
configure: WARNING: ffmpeg/avcodec.h: check for missing prerequisite headers?
configure: WARNING: ffmpeg/avcodec.h: see the Autoconf documentation
configure: WARNING: ffmpeg/avcodec.h: section "Present But Cannot Be Compiled"
configure: WARNING: ffmpeg/avcodec.h: proceeding with the compiler's result
configure: WARNING: ## -------------------------------------------------------- ##
configure: WARNING: ## Report this to opencvlibrary-devel@lists.sourceforge.net ##
configure: WARNING: ## -------------------------------------------------------- ##
明明找到了文件,却不可以用,网上找了好几个小时,也没什么结果,后来经网上http://forums.vega-strike.org/viewtopic.php?f=5&t=11064帖子提示,去看config.log,发现在检查文件可用性的时候,出现了这个问题,导致文件检测到了,不可用

configure:18081: checking ffmpeg/avcodec.h usability
configure:18081: arm-none-linux-gnueabi-g++ -c -I/usr/local/arm/4.3.2/include conftest.cpp >&5
In file included from /usr/local/arm/4.3.2/include/ffmpeg/libavutil/avutil.h:81,
from /usr/local/arm/4.3.2/include/ffmpeg/avcodec.h:30,
from conftest.cpp:64:
/usr/local/arm/4.3.2/include/ffmpeg/libavutil/common.h: In function 'int32_t av_clipl_int32(int64_t)':
/usr/local/arm/4.3.2/include/ffmpeg/libavutil/common.h:154: error: 'UINT64_C' was not declared in this scope

接着这个问题找,很快解决问题,这篇帖子http://code.google.com/p/ffmpegsource/issues/detail?id=11,给出了方法,就是加配置脚本中加入
CXXFLAGS=-D__STDC_CONSTANT_MACROS,形成如下配置文件,这个是ffmpeg的问题,不知道高版本的解决了没有,回头试试去
./configure --host=arm-none-linux-gnueabi --without-gtk --without-carbon --without-quicktime --without-1394libs --with-ffmpeg --without-python --without-swig --disable-apps --enable-shared GXX=arm-linux-g++ CPPFLAGS=-I/usr/local/arm/4.3.2/include LDFLAGS=-L/usr/local/arm/4.3.2/lib --prefix=/usr/local/arm/4.3.2 CXXFLAGS=-D__STDC_CONSTANT_MACROS
心想,现在应该没问题啦吧,结果又出现了更恶劣的问题,也就是标题的问题,出现了这个错误
checking ffmpeg/avformat.h presence... yes
checking for ffmpeg/avformat.h... yes
checking libavformat/avformat.h usability... yes
checking libavformat/avformat.h presence... yes
checking for libavformat/avformat.h... yes
checking for library containing avcodec_decode_video... no
论坛里面也有一个朋友遇到了这个问题,但是他说是编译器问题,可是我本身就4.3.2的编译器,没办法换了,只能硬着头皮上网找,找来找去,又过了好几个小时,依旧没有进展。快放弃了,结果想到了config.log,认真看看,发现下面的提示

configure:18106: checking for library containing avcodec_decode_video
configure:18137: arm-none-linux-gnueabi-g++ -o conftest -D__STDC_CONSTANT_MACROS -I/usr/local/arm/4.3.2/include -L/usr/local/arm/4.3.2/lib conftest.cpp -lrt -lpthread -ldl -lm >&5
/tmp/ccG29wUk.o: In function `main':
conftest.cpp:(.text+0x8): undefined reference to `avcodec_decode_video'
configure:18137: arm-none-linux-gnueabi-g++ -o conftest -D__STDC_CONSTANT_MACROS -I/usr/local/arm/4.3.2/include -L/usr/local/arm/4.3.2/lib conftest.cpp -lavcodec -lrt -lpthread -ldl -lm >&5
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: warning:libavutil.so.50, needed by /usr/local/arm/4.3.2/lib/libavcodec.so, not found (try using -rpath or -rpath-link)
/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/../../../../arm-none-linux-gnueabi/bin/ld: warning:libx264.so.120, needed by /usr/local/arm/4.3.2/lib/libavcodec.so, not found (try using -rpath or -rpath-link)

终于看到了让我兴奋的东西,赶紧试试,把这两个库直接添加到编译选项中,LIBS="-lavutil -lx264",形成最终的配置脚本
[root@RC-ATF OpenCV-2.0.0]# ./configure --host=arm-none-linux-gnueabi --without-gtk --without-carbon --without-quicktime --without-1394libs --with-ffmpeg --without-python --without-swig --disable-apps --enable-shared GXX=arm-linux-g++ CPPFLAGS=-I/usr/local/arm/4.3.2/include LDFLAGS=-L/usr/local/arm/4.3.2/lib --prefix=/usr/local/arm/4.3.2 CXXFLAGS=-D__STDC_CONSTANT_MACROS LIBS="-lavutil -lx264
原创粉丝点击