Amadeus
Amadeus

Reputation: 352

Opencv linker error while cross-compiling the sample cpp (libopencv_calib3d.so: could not read symbols)

I am trying to cross compile a sample OpenCV cpp code for my beaglebone which has a ARM Cortex A8 based AM3359 processor. However when I start the cross-compiling I get the following error:

/usr/local/lib/libopencv_calib3d.so: could not read symbols: File in wrong format collect2: ld returned 1 exit status

It seems like a linker error. I am pretty sure that there is nothing wrong with libopencv_calib3d.so. Because when I compile the program for my PC, everything works fine. Therefore maybe the problem is with the method that I am using for cross compiling. Here is what I do:

I wrote a script in the name of 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%.*}"

and then added it to bashrc:

alias opencv_arm="~/.compile_opencvarm.sh"

Now when I do:

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

Only difference with compiling script and cross-compiling script is that I used arm-linux-gnueabi prefix in the cross-compiling script. When I only compile the cpp file:

root@ghostrider:/home/zero/Desktop# opencv peopledetect.cpp 
compiling peopledetect.cpp
Output file => peopledetect

Everything is OK. Program is executable.

Now what do you think my problem is? Is it a linker error or is it related to my cross-compiling process?

Regards

edit: Oh, now I noticed that I did not install arm-based cross libraries before the arm-linux-gnueabi compiler used them. So I installed them with:

sudo xapt -a armel -m libv4l-dev libgtk2.0-dev libcv-dev libcvaux-dev libhighgui-dev

and edited the script as following:

arm-linux-gnueabi-g++ -ggdb `arm-linux-gnueabi-pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `arm-linux-gnueabi-pkg-config --libs opencv`;

But now I get the problem:

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

Upvotes: 0

Views: 4240

Answers (2)

Paul
Paul

Reputation: 1

I followed this guide but "lnclude/opencv2" directory in the root of opencv distributive is empty after the building. So in fact i have libraries but dont have headers. What am i doing wrong?

UPD: I should be a little more careful, all answers in http://processors.wiki.ti.com/index.php/Building_OpenCV_for_ARM_Cortex-A8

Upvotes: 0

Amadeus
Amadeus

Reputation: 352

I solved my problem by cross-compiling all the OpenCV libraries by following this guide: http://processors.wiki.ti.com/index.php/Building_OpenCV_for_ARM_Cortex-A8

Upvotes: 0

Related Questions