0

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 Answers 3

4

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

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


then compile
./run

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.