0

I'm trying to cross compile a really simple OpenCV app for ARM platform from Ubuntu 14.04

#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>

using namespace cv;

using namespace std;

main(int argc, char *argv[])
{
    Mat img = imread("/home/linaro/Desktop/test.jpg", CV_LOAD_IMAGE_COLOR), grey_img;

    if(!(img.data))
    {
        printf("cannot read image data");
        exit(1);
    }

    cvtColor(img, grey_img, CV_BGR2GRAY);

    imwrite("/home/linaro/Desktop/grey_test.jpg", grey_img);
}

I try to compile like this

arm-linux-gnueabi-g++ opencv_grey.cpp -o grey -I /home/me/c_projects/arm_platform/armcv_build/install/include/opencv -I /home/me/c_projects/arm_platform/armcv_build/install/include/opencv2  -L /home/me/c_projects/arm_platform/armcv_build/install/lib -lopencv_core -lopencv_imgproc -lopencv_highgui

But I get the error

/tmp/ccdN4trw.o: In function `main':
opencv_grey.cpp:(.text+0x84): undefined reference to `cv::imread(std::string const&, int)'
opencv_grey.cpp:(.text+0x168): undefined reference to `cv::imwrite(std::string const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status

These should be opencv_core which I've linked.

The includes and libraries were built and installed using CMake (from the OpenCV 3.0.0.zip), and they're definitely there, I can see them!

Help please, why is this happening?

Wandering Fool
  • 2,170
  • 3
  • 18
  • 48
Mark Corrigan
  • 544
  • 2
  • 11
  • 29
  • Did [this answer](http://stackoverflow.com/questions/7816607) not work? – Drew Dormann Aug 10 '15 at 14:21
  • I saw that, my linking is done after the sources are mentioned and the order was copied from elsewhere so would assume it'd be fine – Mark Corrigan Aug 10 '15 at 14:41
  • Looks like `/home/me/c_projects/arm_platform/armcv_build/install/lib/opencv_core.so` is ignored by the linker for some reason. Are you sure that this library is also cross-compiled for arm? – Tsyvarev Aug 10 '15 at 19:35
  • They're the libraries that CMake built after I chose arm-linux as the platform – Mark Corrigan Aug 10 '15 at 21:46
  • If I use the shared object in the compile how would that look (in terms of syntax and order)? It's there for sure - as is imgproc which is lt seems to link without a complaint! – Mark Corrigan Aug 10 '15 at 21:52

1 Answers1

0

Maybe you can try to add all -lopencv_xxx after:

arm-linux-gnueabi-g++ opencv_grey.cpp -o grey -I /home/me/c_projects/arm_platform/armcv_build/install/include/opencv -I /home/me/c_projects/arm_platform/armcv_build/install/include/opencv2  -L /home/me/c_projects/arm_platform/armcv_build/install/lib -lopencv_core -lopencv_imgproc -lopencv_highgui
ventaquil
  • 2,780
  • 3
  • 23
  • 48