title: Opencv linker error while cross-compiling the sample cpp (libopencv_calib3d.so: could not read symbols)
body: <p>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:</p>
  
  <p>/usr/local/lib/libopencv_calib3d.so: could not read symbols: File in wrong format
  collect2: ld returned 1 exit status</p>
  
  <p>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:</p>
  
  <p>I wrote a script in the name of compile_opencvarm.sh:</p>
  
  <pre><code>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 =&gt; ${1%.*}"
  </code></pre>
  
  <p>and then added it to bashrc:</p>
  
  <pre><code>alias opencv_arm="~/.compile_opencvarm.sh"
  </code></pre>
  
  <p>Now when I do:</p>
  
  <pre><code>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 =&gt; peopledetect
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>root@ghostrider:/home/zero/Desktop# opencv peopledetect.cpp 
  compiling peopledetect.cpp
  Output file =&gt; peopledetect
  </code></pre>
  
  <p>Everything is OK. Program is executable.</p>
  
  <p>Now what do you think my problem is? Is it a linker error or is it related to my cross-compiling process?</p>
  
  <p>Regards</p>
  
  <p>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:</p>
  
  <pre><code>sudo xapt -a armel -m libv4l-dev libgtk2.0-dev libcv-dev libcvaux-dev libhighgui-dev
  </code></pre>
  
  <p>and edited the script as following:</p>
  
  <pre><code>arm-linux-gnueabi-g++ -ggdb `arm-linux-gnueabi-pkg-config --cflags opencv` -o `basename $1 .cpp` $1 `arm-linux-gnueabi-pkg-config --libs opencv`;
  </code></pre>
  
  <p>But now I get the problem:</p>
  
  <pre><code>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&amp;)'
  /home/zero/Desktop/peopledetect.cpp:84: undefined reference to     `cv::HOGDescriptor::detectMultiScale(cv::Mat const&amp;, std::vector&lt;cv::Rect_&lt;int&gt;,  std::allocator&lt;cv::Rect_&lt;int&gt; &gt; &gt;&amp;, double, cv::Size_&lt;int&gt;, cv::Size_&lt;int&gt;, double, double, bool) const'
   /tmp/ccDzUCLJ.o: In function `cv::Mat::operator=(cv::Mat const&amp;)':
   /usr/include/opencv2/core/mat.hpp:317: undefined reference to `cv::Mat::copySize(cv::Mat     const&amp;)'
  /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&lt;float&gt;':
   /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 =&gt; peopledetect
  </code></pre>