Arm-linux交叉编译笔记+opencv 编译

                    Arm-linux交叉编译笔记

一:关于交叉编译器的安装
1、libz的交叉编译:

./configure –prefix=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi –shared

修改makefile
CC=arm-linux-gcc
AR=arm-linux-ar rc
RANLIB=arm-linux-ranlib
CDSHARED=arm-linux-gcc -shared -wl, -soname,libz.so.1,–version-script,zl
lib.map

make

make install

2、libjpeg的交叉编译:

./configure –host=arm-linux –prefix=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi –enable-shared –enable-static

make install

3、libpng的交叉编译

./configure –host=arm-linux –prefix=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi –enable-shared –enable-static

make

make install

4、yasm的交叉编译:

./configure –host=arm-linux –prefix=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi –enable-shared –enable-static

make

make install

5、libx264的交叉编译:

CC=arm-linux-gcc ./configure –enable-shared –host=arm-linux –disable-asm –prefix=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi

make

make install

6、libxvid的交叉编译:

cd build/generic

./configure –prefix=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi –host=arm-linux –disable-assembly

make

make install

7、ffmpeg的交叉编译:

./configure –prefix=/opt/FriendlyARM/toolschain/4.5.1/arm-none-linux-gnueabi –enable-shared –disable-static –enable-gpl –enable-cross-compile –arch=arm –disable-stripping –target-os=linux –enable-libx264 –enable-libxvid –cc=arm-linux-gcc –enable-swscale

make

make install

8.cmake-gui安装
到官网上下载已经编译好的cmake-2.8.8-Linux-i386.tar,gz,解压就可以了。
说明:关于交叉编译器,友善提供完全编译好的,只需要解压到指定目录就可以了。
利用—C加绝对路径。
二:关于opencv的安装
1:安装到电脑
1:下载相应的包,解压到你执念想安装的目录下。
2:cd opencv (mkdir bulid) (cd bulid) 然后,网上有好多方法cmake…….一大串。看着很复杂。这里我实践的,只需要”cmake .”就可以了,这样默认的目录就是usr/local(安装目录)。
说明:这里,若果想要用到cmake的图形化界面,也可以apt-get install cmake-gui。然后cmake-gui就可以了,里面有安装源选择,安装目录选择,还有编译器选择。
3:然后make 说明:编译这个比较慢。可以用make-jx,x代表你的电脑的核。若果是8核,可以用make-j7.分为7个线程去编译它。这样比make快的多。
4:make install。完成。
说明:可以直接用,不用设置环境变量。应为默认的库是usr/loca,你的位置也在这。三:关于交叉编译opencv
1. #mkdir build

cd build

cmake-gui

选择源代码目录/home/6410/opencv/opencv-2.4.2/
选择Build目录:/home/6410/opencv/opencv-2.4.2/build
点击Configure,保持generator为Unix Makefiles,选择Specify options for cross-compiling,点击Next,
Operating System填写arm-linux
C Compilers填写opt/FriendlyARM/toolschain/4.5.1/bin/arm-linux-gcc
C++ Compilers填写opt/FriendlyARM/toolschain/4.5.1//bin/arm-linux-g++
程序库的Target Root填写opt/FriendlyARM/toolschain/4.5.1/
然后点击Finish。
默认安装目录为/usr/local,点击Generate生成Makefile。

make

2,在/usr/local/opencv-arm目录下$sudo make
(1),80%报错:
。。。。/home/xin/tiaozhansai/OpenCV-2.2.0/modules/ml/src/gbt.cpp:474: error: ‘expl’ was not declared in this scope
修改gbt.cpp中14行,16行:注释掉
//#if ANDROID
#define expl(x) exp(x)
//#endif
错误消除。

(2),83%报错:
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libopencv_core.so: undefined reference to clock_gettime'
../../lib/libopencv_highgui.so: undefined reference to
_TIFFerrorHandler’
../../lib/libopencv_highgui.so: undefined reference to _TIFFrealloc'
../../lib/libopencv_core.so: undefined reference to
pthread_key_create
解决方法:修改CMakeCache.txt,CMAKE_EXE_LINKER_FLAGS原来为空,加上-lpthread -lrt,重新编译,错误消除

(3),83%报错:
Linking CXX executable ../../bin/opencv_createsamples
../../lib/libopencv_highgui.so: undefined reference to _TIFFerrorHandler'
../../lib/libopencv_highgui.so: undefined reference to
_TIFFrealloc’
../../lib/libopencv_highgui.so: undefined reference to _TIFFmalloc'
../../lib/libopencv_highgui.so: undefined reference to
_TIFFmemcpy’
../../lib/libopencv_highgui.so: undefined reference to TIFFOpen'
../../lib/libopencv_highgui.so: undefined reference to
_TIFFfree’
../../lib/libopencv_highgui.so: undefined reference to _TIFFwarningHandler'
../../lib/libopencv_highgui.so: undefined reference to
_TIFFmemcmp’
../../lib/libopencv_highgui.so: undefined reference to `_TIFFmemset’
解决方法:修改CMakeCache.txt,WITH_TIFF:BOOL=ON,改成OFF(不再对TIFF图像格式支持。这里我前面已经装过libtiff4-dev,但是编译报错,我不明白是为什么),重新编译,错误消除。

(4),96%报错:
CMakeFiles/opencv_test.dir/src/highguitest.obj: In function CV_HighGuiTest::run(int)':
highguitest.cpp:(.text._ZN14CV_HighGuiTest3runEi+0x18): warning: the use of
tmpnam’ is dangerous, better use mkstemp'
../../lib/libopencv_features2d.so: undefined reference to
cv::SIFT::SIFT(double, bool, bool, int, int, int, int)’
解决方法:在OpenCV2.2.0/modules/features2d/src/sift.cpp下
#ifdef arm
#define ARM_NO_SIFT
#endif
注释掉#define ARM_NO_SIFT.错误消除,
成功!

$sudo make install
3、测试
测试代码自己动手
遇到的问题:1.要用arm-linux-gxx去编译,xx:是c用gcc。c++
用g++。但是会有很多问题。
若出现头文件找不到:
方法一:用echo ‘main(){}’|arm-linux-gcc -E -v -默认搜索路径。把usr/local下的opencv复制到这个目录下。

方法二:自己写pkg文件,告诉编译器你的文件在哪儿。
我写的pkg:# package Information for pkg-config

prefix=/usr/local/opencv-arm
exec_prefix= prefixlibdir= p r e f i x l i b d i r = {exec_prefix}/lib
includedir_old= prefix/include/opencvincludedirnew= p r e f i x / i n c l u d e / o p e n c v i n c l u d e d i r n e w = {prefix}/include

Name:Opencv
Description:Open source Computer Vision Library
Version:2.3.1
Libs:-L libdirlopencvcorelopencvimgprolopencvhighguilopencvmllopencvvideolopencvfeatures2dlopencvcalibd3lopencvobjdetectlopencvcontriblopencvlegacylopencvflannCflags:I l i b d i r − l o p e n c v c o r e − l o p e n c v i m g p r o − l o p e n c v h i g h g u i − l o p e n c v m l − l o p e n c v v i d e o − l o p e n c v f e a t u r e s 2 d − l o p e n c v c a l i b d 3 − l o p e n c v o b j d e t e c t − l o p e n c v c o n t r i b − l o p e n c v l e g a c y − l o p e n c v f l a n n C f l a g s : − I {includedir_old} -I${includedir_new}
自己照例子

方法三:自己写makeflie,指定头文件路径。
还有会出现note: the mangling of ‘va_list’ has changed in GCC
方法一:g++ += -std=c++0x -USTRICT_ANSI
方法二:#arm-linux-g++ -Wno-psabi hello.c -o hello pkg-config --cflags --libs opencv (亲测有用)
还要加-lpthread –lrt,前面改了标识。后面编译要加。例如 arm-linux-g++ –o test pkg-config --cflags opencv-arm pkg-config –libs opencv-arm -Wno-psabi test.cpp -lpthread –lrt
如果没问题就是成功了。
若果出现
arm-linux-g++: –o: No such file or directory
arm-linux-g++: test: No such file or directory
arm-linux-g++: –lrt: No such file or directory
就是还有问题,要装一个sudo apt-get install ia32-libs
这个库。64为版本不支持。如果出现,没有这个源,那么对不起,我也卡这儿了。渍渍渍

4.移植
以后编译arm板的OpenCV代码时,要使用上面的编译指令。其中` 符号不是逗号,而是1 左边的那个符号。而把编译好的程序放到arm板时,在运行之,还要把/usr/local/arm-opencv/lib目录下的所有.so文件都拷贝到arm的/usr/lib或者/lib目录下。
头文件也要复制过去,在usr/local/opencv下面。
然后over

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lobmo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值