OpenCV: cannot compile when using imwrite() function
Asked Answered
H

1

5

In my simple first OpenCV application I want to save frames got by cam so I am using imwrite() as tutorial say. The problem, is that I can't compile because I get this error:

Undefined symbols for architecture x86_64:
"cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int,  std::allocator<int> > const&)", referenced from:
_main in video-87ad7a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Reading some posts here in SO I have discovered it's a problem about the C++ standard library which is used, so I added the flag libstdc++ but the following:

g++ -stdlib=libstdc++ -I/usr/local/include -L/usr/local/lib/ -g -o binary video.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_stitching -lopencv_videoio -lopencv_videostab

has not solved the problem. How shall I do?

UPDATE it seems this is the solution. I don't know what was the damned flag I was missing

Haynor answered 27/1, 2016 at 23:53 Comment(0)
M
15

Looks like you are missing '-lopencv_imgcodecs' where imwrite() lives.
Refer to OpenCV imgcodecs header file here.

Miller answered 28/1, 2016 at 2:49 Comment(1)
Interesting thing - when I switched to the clang, I started to get that error, even though previously with gcc it worked without problems.Impel

© 2022 - 2024 — McMap. All rights reserved.