Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV: cannot compile when using imwrite() function

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

like image 661
SagittariusA Avatar asked Dec 09 '22 00:12

SagittariusA


1 Answers

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

like image 130
Dufus Johnson Avatar answered Dec 11 '22 12:12

Dufus Johnson