|
楼主 |
发表于 2009-2-19 15:58:34
|
显示全部楼层
OpenCV在Blackfin-uClinux下的使用测试问题
问题1:
bfin-uclinux-g++ -O2 -Wall -Dlinux -D__linux__ -Dunix -D__uClinux__ -DEMBED -fno-builtin -I/HHBF531-R1/uClinux-dist -I/HHBF531-R1/uClinux-dist/linux-2.6.x/include -I./ -c -o hello.o hello.c
改成
bfin-uclinux-gcc
因为g++会按照c++的方式去处理hello.c中的symbol,处理之后的cvNamedWindow可能跟libcv.a中的该函数不一样了。
既然错误提示已经给出来了,那你可以这样看看:
bfin-uclinux-objdump -S libcv.a | grep cvNamedWindow(这里假设这个函数是在livcv.a中),看看在libcv.a中的函数token是什么。
最后链接的时候,如果所有库都是用gcc生成的,那么链接的时候也要用gcc,不要用g++。另外,删掉链接命令中hello.o后边的libcv.a,是多余的。
问题2:
-lpthread只是指定链接posix thread库,链接器会自行检查是否有用到这个库中的函数,不见得会有什么实质影响。
问题3:
如果仍然出现highgui的函数链接找不到,试试这样,把所有的库写两遍,即:
-lcxcore -lcv -lhighgui -lcvaux -lml -lpthread
变成
-lcxcore -lcv -lhighgui -lcvaux -lml -lpthread -lcxcore -lcv -lhighgui -lcvaux -lml -lpthread
如果仍然不行,你要给出更加详细的错误描述和输出信息。
问题4:
undefined instruction,首先你要搞懂这是什么意思。
未定义的指令,这类异常通常是由于除0或是浮点运算引起的。从编译命令来看,你用的是uclinux,而uclinux缺省使用uclibc,uclibc缺省可能不支持浮点运算。
解决方法,你可能要重新编译uclibc和uclinux,并且在编译这两者时都要指定使用soft-float,即软件模拟浮点运算。
RE Q1:重新检查了./configure的信息,并且看到make时的编译信息,确认编译库的时候用的是bfin-uclinux-g++,所以编译和链接测试程序hello.c时也使用的是bfin-uclinux-g++。
- ./configure --build=i686-pc-linux-gnu --host=bfin-unknown-uclinux --without-gtk --without-carbon --without-quicktime --without-1394libs--without-swig --without-python --enable-static --disable-shared --disable-apps CC=bfin-uclinux-gcc CXX=bfin-uclinux-g++
复制代码 输出信息为:- General configuration
- =============================================
- Compiler: bfin-uclinux-g++
- CXXFLAGS: -Wall -fno-rtti -pipe -O3 -fomit-frame-pointer
- Install path: /usr/local
复制代码 使用bfin-uclinux-g++编译hello.c时,正常通过,无任何提示;链接时出现错误: undefined reference to "_cvNamedWindow";
而相同条件下使用bfin-uclinux-gcc编译hello.c时,编译通过,但有警告: \'cv...\' defined but not used ;链接时出现新的错误:- hello.elf2flt(.text+0x202): In function `_main\':
- : undefined reference to `_cvNamedWindow\'
- hello.elf2flt(.text+0x128b0): In function `icvThickLine(CvMat*, CvPoint, CvPoint, void const*, int, int, int, int)\':
- cxdrawing.cpp: undefined reference to `_sqrt\'
- hello.elf2flt(.eh_frame+0x11): undefined reference to `___gxx_personality_v0\'
- hello.elf2flt(.eh_frame+0xa8d): undefined reference to `___gxx_personality_v0\'
- hello.elf2flt(.eh_frame+0xbb9): undefined reference to `___gxx_personality_v0\'
- hello.elf2flt(.eh_frame+0x161d): undefined reference to `___gxx_personality_v0\'
- hello.elf2flt(.eh_frame+0x19b1): undefined reference to `___gxx_personality_v0\'
- hello.elf2flt(.eh_frame+0x1a21): more undefined references to `___gxx_personality_v0\' follow
- collect2: ld returned 1 exit status
复制代码
RE Q2:加入-lpthread后错误减少,不过确实没有实质影响,主要是highgui库的问题。
RE Q3:看过这种解决方法,试了试,没有效果,但在后来的命令中一直保持这种命令方法。
RE Q4:这个问题应该就是浮点运算引起的,使用软件模拟浮点运算,或者进行算法移植,将浮点改成定点运算,应该可以消除。大概这就是为什么简单OpenCV函数能够在目标板运行,而复杂的函数则会出现 undefined instruction 错误的原因。看到有篇论文讲到相关的一些信息:The OpenCV library uses floating point arithmetic whereas the Blackfin has no hardware support for it. In order for the programs not to run too slow on the Blackfin board, they have to be optimized. The Blackfin cross-compiler provides a soft float point library which emulates floating point arithmetic. This library is especially optimized for the Blackfin. By using the soft float point library, the execution time of the programs can be reduced by a 2 factor. 如果想得到较为理想的运算效果的话,还是需要将算法中的浮点运算转换成定点运算。 |
|