0
votes

I'm just starting with OpenCV and am stuck running the sample code on this website.

I made a .cpp file and copy/pasted the code in.

I ran the following command on the command line:

g++ program.cpp -o program

I got the following errors:

undefined reference to `cv::imread(cv::String const&, int)'

program.cpp:(.text+0x128): undefined reference to `cv::namedWindow(cv::String const&, int)'

program.cpp:(.text+0x17d): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'

program.cpp:(.text+0x1a5): undefined reference to `cv::waitKey(int)'

/tmp/cceJEar6.o: In function `cv::String::String(char const*)':

program.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x4d): undefined reference to `cv::String::allocate(unsigned long)'

It seems to be a linking problem where it can't find the cv namespace or the opencv libraries

3

3 Answers

4
votes

You haven't specified the OpenCV libraries while compiling. Use this command:

g++ `pkg-config --cflags opencv` codename.cpp `pkg-config --libs opencv` -o codename
0
votes

You have to specify the library files as linker flags.

g++ program.cpp -o program -lopencv_core -lopencv_highgui

For this specific program, only the core and highgui modules of OpenCV are required. The list will increase as functionality from other modules are added in the program.

0
votes
g++ -ggdb `pkg-config --cflags opencv` -o outResize *.cpp `pkg-config --libs opencv`


then compile
./run