linux - 在 CMake Linux 中包含 OpenCV

标签 linux opencv makefile cmake

昨天我制作了一个“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_coreopencv_highguiopencv_imgproc 等...

如果您从源代码编译库,则在从名称中减去 lib 前缀后,库名称将在 /usr/local/lib 中找到。

关于linux - 在 CMake Linux 中包含 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15887759/

相关文章:

python - 如何使用openCV和HAAR Cascades进行人脸模糊?

python - OpenCv索引如何工作?

Linux "make"命令错误127

c - 为什么 LDFLAGS 将我的库放在生成 undefined reference 的目标文件之前?

c++ - GNU make 有时不在 VPATH 中声明的文件夹中搜索

c - 运行 make install 时出错 - 缺少 include/generated/autoconf.h 或 include/config/auto.conf

linux - MonoDevelop 不工作(安装了 xterm)

Linux内核模块编译失败

c++ - 我想在窗口中保留一个填充的矩形,但失败了。请告诉我为什么。

linux - 查询最近卸载的rpm包