How to get opencv include work in kubuntu? (Includes solution to how to include and link in netbeans 6.7.1)

StackOverflow https://stackoverflow.com/questions/2128851

Question

I have installed OpenCV C libraries from package management into my Kubuntu 9.10. I wrote a small image modification program that uses those libraries, but I can't compile it, because every time I try to compile I get the error message that the functions from OpenCV library cannot be found.

Those header files are in folder /usr/include/opencv/ but still the compiler says that functions cannot be found.

I have tried to include them by basic

#include <highgui.h>
#include <cv.h>

commands in netbeans (and I have set netbeans to search header files from that specific directory) and also tried to include them with full path.

#include </usr/include/opencv/highgui.h>
#include </usr/include/opencv/cv.h>

Also I tried to compile my source file in console (with full path includes), but again I got the same error message that the functions from those libraries cannot be found.

Edit:

The error message that I get is

undefined reference to 'function_name'

I get that error for every function that I try to use from that opencv library.

Any idea how to fix that problem?


Edit II:

in case someone else is using netbeans 6.7.1 and has the same problem, here's the solution copy pasted from another website:

Here I presume that you have succesfully installed the opencv library either manually or via package management.

  1. Open Netbeans then do the following: Select Tools -> Options -> C/C++ -> Code Assistance -> add Include Directories (For me, /usr/local/include/opencv)
  2. Create new project, then: Right click on Project Name -> Properties ->Build -> C/C++ Compiler -> Include Directories Include Directories : /usr/local/include/opencv
  3. Right click on Project Name -> Properties -> Build -> linker -> Include Directories : /usr/local/include/opencv Additional Options : -I/usr/local/include/opencv -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux -lml

Then writing program and compile!!

Was it helpful?

Solution

"undefined reference to" is a linker error. You forgot to link your application against the OpenCV libraries. Make sure you link against cv and highgui (-lcv -lhighgui) or use the pkg-config call that Tobu provided. I'd also second the request for more detailed error messages.

OTHER TIPS

OpenCV uses pkg-config, the standard way to locate libraries and headers on unix. You can run (untested):

make CFLAGS="$(pkg-config --cflags --libs opencv)" your-program
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top