交叉编译示例cpp时出现Opencv链接器错误(libopencv_calib3d.so:无法读取符号)

交叉编译示例cpp时出现Opencv链接器错误(libopencv_calib3d.so:无法读取符号),opencv,linker,cross-compiling,ubuntu-12.04,Opencv,Linker,Cross Compiling,Ubuntu 12.04,我正在尝试为我的beaglebone交叉编译一个示例OpenCV cpp代码,它有一个基于ARM Cortex A8的AM3359处理器。但是,当我开始交叉编译时,出现以下错误: /usr/local/lib/libopencv_calib3d.so:无法读取格式错误的符号:文件 collect2:ld返回了1个退出状态 这似乎是一个链接器错误。我很确定libopencv_calib3d没有什么问题。因为当我为我的电脑编译程序时,一切都很好。因此,问题可能在于我用于交叉编译的方法。以下是我的工作

我正在尝试为我的beaglebone交叉编译一个示例OpenCV cpp代码,它有一个基于ARM Cortex A8的AM3359处理器。但是,当我开始交叉编译时,出现以下错误:

/usr/local/lib/libopencv_calib3d.so:无法读取格式错误的符号:文件 collect2:ld返回了1个退出状态

这似乎是一个链接器错误。我很确定libopencv_calib3d没有什么问题。因为当我为我的电脑编译程序时,一切都很好。因此,问题可能在于我用于交叉编译的方法。以下是我的工作:

我以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
root@ghostrider:/home/zero/Desktop#opencv_arm peopledetect.cpp
编译peopledetect.cpp
/usr/lib/gcc/arm-linux-gnueabi/4.6/../../../../../../../../../../../arm-linux-gnueabi/bin/ld:警告:liblapack.so.3gf,未找到/usr/arm-linux-gnueabi/lib/libcxcore.so所需的文件(尝试使用-rpath或-rpath链接)
/tmp/ccDzUCLJ.o:在函数“main”中:
/home/zero/Desktop/peopledetect.cpp:49:对“cv::HOGDescriptor::SetSVMDetor(cv:_InputArrayconst&)”的未定义引用
/home/zero/Desktop/peopledetect.cpp:84:未定义对“cv::HOGDescriptor::detectMultiScale(cv::Mat const&,std::vector&,double,cv::Size_,cv::Size_,double,double,bool)const”的引用
/tmp/ccDzUCLJ.o:在函数“cv::Mat::operator=(cv::Mat const&)”中:
/usr/include/opencv2/core/mat.hpp:317:对“cv::mat::copySize(cv::mat const&)”的未定义引用
/tmp/ccDzUCLJ.o:在函数'cv::Mat::release()'中:
/usr/include/opencv2/core/mat.hpp:382:对'cv::mat::deallocate()'的未定义引用
/tmp/ccDzUCLJ.o:在函数“输入阵列”中:
/usr/include/opencv2/core/mat.hpp:1108:vtable for cv:
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dgelsd”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dpotrf”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dpotri”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dsyevr”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dgesv_”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dpotrs”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dgetri_”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“sgels_2;”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“sgesv_”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dgetrf”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“sgetrf_2;”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dgels”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“spotrf\ux”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“sgelsd”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“sgesdd_2;”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“spotri_2;”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“ssyevr_2;”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“dgesdd_2;”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“spotrs”的引用
/usr/arm-linux-gnueabi/lib/libcxcore.so:未定义对“sgetri\ux”的引用
collect2:ld返回了1个退出状态
输出文件=>peopledetect

我按照本指南交叉编译了所有OpenCV库,从而解决了我的问题:

我遵循了本指南,但在构建之后,OpenCV distributive根目录中的“include/opencv2”目录为空。所以事实上我有库,但没有标题。我做错了什么


UPD:我应该更仔细一点,所有答案都在

中,你是如何编译你的程序的?pkg config仍然指向x86目录。