昨天我制作了一个“CMakeLists.txt”文件,其中包含以下内容。
cmake_minimum_required(VERSION 2.8)
project( HMirror )
find_package( OpenCV REQUIRED )
add_executable( HMirror HMirror.cpp )
target_link_libraries( HMirror ${OpenCV_LIBS} )
它工作正常,我没有改变任何东西......(真的!!!!)
今天我想在我的代码中添加一些额外的功能,我在我的 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&)'
从昨天开始,我就没有更改过库目标,也没有更改过代码。所以我想知道为什么它似乎不再起作用了。
最佳答案
尝试明确写出要链接的库。在 Linux 上,这将是 opencv_core
、opencv_highgui
、opencv_imgproc
等...
如果您从源代码编译库,则在从名称中减去 lib 前缀后,库名称将在 /usr/local/lib
中找到。
关于linux - 在 CMake Linux 中包含 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15887759/