Including OpenCV with CMake Linux

2019-08-04 08:51发布

yesterday I made a "CMakeLists.txt" file, that contained the following.

cmake_minimum_required(VERSION 2.8)
project( HMirror )
find_package( OpenCV REQUIRED )
add_executable( HMirror HMirror.cpp )
target_link_libraries( HMirror ${OpenCV_LIBS} )

It worked fine, I havent Changed anything.... (really!!!!)

Today as I wanted to Add some Extra functions to my Code I got the following Output on my Linux Shell.

HMirror.cpp:(.text+0x56): undefined reference to `cv::imread(std::string const&, int)'
HMirror.cpp:(.text+0x191): undefined reference to `cv::namedWindow(std::string const&, int)'
HMirror.cpp:(.text+0x1f1): undefined reference to `cv::namedWindow(std::string const&, int)'
HMirror.cpp:(.text+0x268): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
HMirror.cpp:(.text+0x2df): undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'

I haven't changed the librarys destination and havent changed the code since yesterday. So I wonder Why it doesn't seem to work anmore.

1条回答
唯我独甜
2楼-- · 2019-08-04 09:24

Try to write explicitly which libraries to link. On Linux, this would be opencv_core,opencv_highgui,opencv_imgproc, etc...

If You compiled library from sources, the library names would be found in /usr/local/lib, after subtracting lib prefix from names.

查看更多
登录 后发表回答