解决Linux下 C++ opencv 库文件的链接问题

errors:

/home/tonyyan/Documents/main.cpp:108: undefined reference to `cv::VideoCapture::read(cv::_OutputArray const&)'
/home/tonyyan/Documents/main.cpp:130: undefined reference to `cv::putText(cv::_InputOutputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/home/tonyyan/Documents/main.cpp:131: undefined reference to `cv::putText(cv::_InputOutputArray const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Point_<int>, int, double, cv::Scalar_<double>, int, int, bool)'
/home/tonyyan/Documents/main.cpp:134: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)'
/home/tonyyan/Documents/main.cpp:135: undefined reference to `cv::waitKey(int)'
/home/tonyyan/Documents/main.cpp:69: undefined reference to `cv::VideoCapture::~VideoCapture()'
/home/tonyyan/Documents/main.cpp:68: undefined reference to `cv::Mat::~Mat()'
/home/tonyyan/Documents/main.cpp:36: undefined reference to `cv::Mat::~Mat()'
/home/tonyyan/Documents/main.cpp:69: undefined reference to `cv::VideoCapture::~VideoCapture()'
/home/tonyyan/Documents/main.cpp:68: undefined reference to `cv::Mat::~Mat()'
/home/tonyyan/Documents/main.cpp:36: undefined reference to `cv::Mat::~Mat()'

solution:

add the following arguments to g++:

-lopencv_core -lopencv_imgproc -lopencv_highgui

in tasks.json of vscode:

                "-lopencv_core",
                "-lopencv_imgproc",
                "-lopencv_highgui",

  

reference: 

https://stackoverflow.com/questions/24337932/cannot-get-opencv-to-compile-because-of-undefined-references

 

补充 error:

9: undefined reference to `cv::VideoCapture::VideoCapture()'

solution:

"-lopencv_videoio",

 

总之,缺什么就链接什么库文件。

posted @ 2021-06-16 14:26  略略略——  阅读(5185)  评论(0编辑  收藏  举报