我正在尝试为我的beaglebone交叉编译示例OpenCV cpp代码,该代码具有基于ARM Cortex A8的AM3359处理器。但是,当我开始交叉编译时,我收到以下错误:
/usr/local/lib/libopencv_calib3d.so:无法读取符号:文件格式错误 collect2:ld返回1退出状态
这似乎是一个链接器错误。我很确定libopencv_calib3d.so没有任何问题。因为当我为我的电脑编译程序时,一切正常。因此,问题可能在于我用于交叉编译的方法。这是我的工作:
我以compile_opencvarm.sh的名义编写了一个脚本:
echo "Cross-Compiling $1"
if [[ $1 == *.c ]]
then
arm-linux-gnueabi-gcc -ggdb `pkg-config --cflags opencv` -o `basename $1 .c` $1 `pkg-config --libs opencv`;
elif [[ $1 == *.cpp ]]
then
arm-linux-gnueabi-g++ -ggdb `pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `pkg-config --libs opencv`;
else
echo "Please compile only .c or .cpp files with this script"
fi
echo "Cross-Compiled Output => ${1%.*}"
然后将其添加到bashrc:
alias opencv_arm="~/.compile_opencvarm.sh"
现在我做的时候:
root@ghostrider:/home/zero/Desktop# opencv_arm peopledetect.cpp
Cross-Compiling peopledetect.cpp
/usr/local/lib/libopencv_calib3d.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
Cross-Compiled Output => peopledetect
与编译脚本和交叉编译脚本的区别仅在于我在交叉编译脚本中使用了arm-linux-gnueabi前缀。当我只编译cpp文件时:
root@ghostrider:/home/zero/Desktop# opencv peopledetect.cpp
compiling peopledetect.cpp
Output file => peopledetect
一切都好。程序是可执行的。
现在您认为我的问题是什么?它是链接器错误还是与我的交叉编译过程有关?
此致
编辑:哦,现在我注意到我没有在arm-linux-gnueabi编译器使用它们之前安装基于arm的交叉库。所以我用它们安装了它们:
sudo xapt -a armel -m libv4l-dev libgtk2.0-dev libcv-dev libcvaux-dev libhighgui-dev
并编辑脚本如下:
arm-linux-gnueabi-g++ -ggdb `arm-linux-gnueabi-pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `arm-linux-gnueabi-pkg-config --libs opencv`;
但现在我遇到了问题:
root@ghostrider:/home/zero/Desktop# opencv_arm peopledetect.cpp
compiling peopledetect.cpp
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../arm-linux-gnueabi/bin/ld: warning: liblapack.so.3gf, needed by /usr/arm-linux-gnueabi/lib/libcxcore.so, not found (try using -rpath or -rpath-link)
/tmp/ccDzUCLJ.o: In function `main':
/home/zero/Desktop/peopledetect.cpp:49: undefined reference to `cv::HOGDescriptor::setSVMDetector(cv::_InputArray const&)'
/home/zero/Desktop/peopledetect.cpp:84: undefined reference to `cv::HOGDescriptor::detectMultiScale(cv::Mat const&, std::vector<cv::Rect_<int>, std::allocator<cv::Rect_<int> > >&, double, cv::Size_<int>, cv::Size_<int>, double, double, bool) const'
/tmp/ccDzUCLJ.o: In function `cv::Mat::operator=(cv::Mat const&)':
/usr/include/opencv2/core/mat.hpp:317: undefined reference to `cv::Mat::copySize(cv::Mat const&)'
/tmp/ccDzUCLJ.o: In function `cv::Mat::release()':
/usr/include/opencv2/core/mat.hpp:382: undefined reference to `cv::Mat::deallocate()'
/tmp/ccDzUCLJ.o: In function `_InputArray<float>':
/usr/include/opencv2/core/mat.hpp:1108: undefined reference to `vtable for cv::_InputArray'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgelsd_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dpotrf_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dpotri_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dsyevr_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgesv_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dpotrs_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgetri_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgels_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgesv_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgetrf_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgetrf_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgels_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `spotrf_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgelsd_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgesdd_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `spotri_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `ssyevr_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `dgesdd_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `spotrs_'
/usr/arm-linux-gnueabi/lib/libcxcore.so: undefined reference to `sgetri_'
collect2: ld returned 1 exit status
Output file => peopledetect
答案 0 :(得分:0)
我通过遵循本指南交叉编译所有OpenCV库来解决我的问题:http://processors.wiki.ti.com/index.php/Building_OpenCV_for_ARM_Cortex-A8
答案 1 :(得分:0)
我遵循了这个指南但是opencv分配根目录中的“lnclude / opencv2”目录在构建之后是空的。所以实际上我有图书馆,但没有标题。我做错了什么?
UPD:我应该更加小心,http://processors.wiki.ti.com/index.php/Building_OpenCV_for_ARM_Cortex-A8
中的所有答案