Error when linking C executable to OpenCV

Posted by Ghilas BELHADJ on Stack Overflow See other posts from Stack Overflow or by Ghilas BELHADJ
Published on 2013-11-06T15:51:50Z Indexed on 2013/11/06 15:53 UTC
Read the original article Hit count: 266

Filed under:
|

I'm compiling OpenCV under Ubuntu 13.10 using cMake.

i've already compiled c++ programs and they works well.

now i'm trying to compile a C file using this cMakeLists.txt

cmake_minimum_required (VERSION 2.8)
project (hello)
find_package (OpenCV REQUIRED)
add_executable (hello src/test.c)
target_link_libraries (hello ${OpenCV_LIBS})

here is the test.c file:

#include <stdio.h>
#include <stdlib.h>
#include <opencv/highgui.h>

int main (int argc, char* argv[])
{
  IplImage* img = NULL; 
  const char* window_title = "Hello, OpenCV!";

  if (argc < 2)
  {
    fprintf (stderr, "usage: %s IMAGE\n", argv[0]);
    return EXIT_FAILURE;
  }
  img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);

  if (img == NULL)
  {
    fprintf (stderr, "couldn't open image file: %s\n", argv[1]);
    return EXIT_FAILURE;
  }
  cvNamedWindow (window_title, CV_WINDOW_AUTOSIZE);
  cvShowImage (window_title, img);
  cvWaitKey(0);
  cvDestroyAllWindows();
  cvReleaseImage(&img);

  return EXIT_SUCCESS;
}

it returns me this error whene running cmake . then make to the project:

Linking C executable hello
/usr/bin/ld: CMakeFiles/hello.dir/src/test.c.o: undefined reference to symbol «lrint@@GLIBC_2.1»
/lib/i386-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [hello] Erreur 1
make[1]: *** [CMakeFiles/hello.dir/all] Erreur 2
make: *** [all] Erreur 2

© Stack Overflow or respective owner

Related posts about opencv

Related posts about linker