0

I am trying to build the program at http://docs.opencv.org/doc/tutorials/introduction/display_image/display_image.html after installing OpenCV on my machine. I try to compile it using g++ display_image.cpp -o DisplayImage but I get the following error:

display_image.cpp:(.text+0x9d): undefined reference to `cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'

I think this has to do with how I'm compiling the program (some unresolved reference to opencv2) but I don't know how to resolve it. I'm using Ubuntu 13.04. Thanks!

Edit: I realize this is similar to OpenCV 2.3 Compiling Issue - Undefined Refence - Ubuntu 11.10 but I don't really understand the use of pkg-config opencv --cflags --libs and how to avoid it

Community
  • 1
  • 1
Ben S
  • 129
  • 1
  • 9
  • 1
    looks like you forget to link with OpenCV lib with a -l or -L.... – alexbuisson Jul 23 '13 at 20:14
  • possible duplicate of [OpenCV 2.3 Compiling Issue - Undefined Refence - Ubuntu 11.10](http://stackoverflow.com/questions/7816607/opencv-2-3-compiling-issue-undefined-refence-ubuntu-11-10) – alexbuisson Jul 23 '13 at 20:21
  • You can't avoid the use of pkg-config... – alexbuisson Jul 23 '13 at 20:26
  • 1
    `pkg-config [package] --cflags --libs` returns the compiler flags and libraries that you need to add to gcc command in order to use `[package]` in your computer. You can avoid the use if you already know the output of that command and use it directly – Zhen Jul 23 '13 at 20:49

1 Answers1

1

You got a linker error because you didn't specify OpenCV on your GCC command line

Follow that tutorial (http://opencv.willowgarage.com/wiki/CompileOpenCVUsingLinux) link your sample with OpenCV

alexbuisson
  • 7,699
  • 3
  • 31
  • 44