C ++ / CMake:在OpenCV中未定义的引用引用 [英] C++/CMake:Undefined reference to imwrite in OpenCV

查看:464
本文介绍了C ++ / CMake:在OpenCV中未定义的引用引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的CMakeLists.txt:

This is my CMakeLists.txt:

project(proj)
set(OpenCV_DIR "/usr/lib/opencv")
find_package(OpenCV REQUIRED COMPONENTS core imgproc highgui)

include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test test.cpp>
target_link_libraries(test ${OpenCV_LIBS})

这是我的代码的一部分:

and this is part of my code:

#include <opencv/cv.h>
#include <opencv/cv.hpp>
#include <opencv/highgui.h>
#include <opencv/highgui.hpp>

using namespace cv;
using namespace std;

int main(int argv, char **argc)
{       
    //other code
    Mat img(height, width, CV_8UC3);
    //other code

    imwrite("/path", img);
    namedWindow( "Display window", 1 );
    imshow("Display window", img);

    waitKey(0);                                          
    return 0;

}

而我得到的错误消息是:

and the error message I get is:

undefined reference to cv::imwrite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::Mat const&, std::vector<int, std::allocator<int> > const&)`

imshow可以正常工作,所以我不知道为什么imwrite给我一个错误。

imshow works correctly, so I have no clue why imwrite is giving me an error.

编辑:

g++ -o test_1 test_1.cpp `pkg-config opencv --cflags --libs`

给出相同的错误。

推荐答案

在您的 find_package()命令中,您仅从 OpenCV 软件包,而您需要的软件包( imgcodecs 却提供了 imwrite())不在

In your find_package() command, you are only selecting some specific modules from the OpenCV package, and the one you need (imgcodecs which provides imwrite()) is not in the list.

尝试将其更改为:

find_package(OpenCV)

这篇关于C ++ / CMake:在OpenCV中未定义的引用引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆