views:

175

answers:

2

Hi,

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!!

A: 

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
Tobu
I tried that, but it didn't work or I'm doing it wrong :) I get the message that says that there's nothing that should be made to my program.
zaplec
If `your-program.c` is the source file, `your-program` doesn't exist yet. Try the command with no extension. Exact copy-pasted messages are also good.
Tobu
+1  A: 

"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.

dseifert
I compiled my program at console using line "gcc myprogram.c -o myprogram -Wall -I /usr/local/include/opencv -L /usr/local/lib -lm -lcv -lhighgui" and that made it work. Thanks for the tip and correction that it was a linker error :)
zaplec