我正在尝试为我的 beaglebone 交叉编译示例 OpenCV cpp 代码,该代码具有基于 ARM Cortex A8 的 AM3359 处理器。但是,当我开始交叉编译时,出现以下错误:
/usr/local/lib/libopencv_calib3d.so:无法读取符号:文件格式错误 collect2:ld 返回 1 退出状态
这似乎是一个链接器错误。我很确定 libopencv_calib3d.so 没有任何问题。因为当我为我的 PC 编译程序时,一切正常。因此,问题可能出在我用于交叉编译的方法上。这是我所做的:
我以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