对cv :: imread(cv :: String const&amp ;, int)的未定义引用 [英] Undefined reference to cv::imread(cv::String const&, int)

查看:1930
本文介绍了对cv :: imread(cv :: String const&amp ;, int)的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV编写简单的代码,但是无法成功编译它.下面是代码:

I am trying to use OpenCV to write a simple code but I am not able to compile it successfully. Below is the code :

#include <iostream>
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

using namespace std;
using namespace cv;

int main()
{
    Mat img = imread("insignia.jpg", -1);
    return 0;
}

,它将不起作用.以下是我收到的错误消息.

and it won't work. Below is the error message I received.

/tmp/ccEMHPHa.o: In function `main':
main.cpp:(.text+0x46): undefined reference to `cv::imread(cv::String const&, int)'
/tmp/ccEMHPHa.o: In function `cv::String::String(char const*)':
main.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x58): undefined reference to `cv::String::allocate(unsigned long)'
/tmp/ccEMHPHa.o: In function `cv::String::~String()':
main.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to `cv::String::deallocate()'
/tmp/ccEMHPHa.o: In function `cv::Mat::~Mat()':
main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference to `cv::fastFree(void*)'
/tmp/ccEMHPHa.o: In function `cv::Mat::release()':
main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): undefined reference to `cv::Mat::deallocate()'
collect2: error: ld returned 1 exit status

我尝试过在线搜索此问题,但是大多数答案都不能解决我的问题.有人可以帮我吗?

I've tried searching for this issue online, but most of the answers didn't solve my problem. Can someone please help me?

推荐答案

这听起来像是链接问题.我可以使用g ++毫无问题地编译您的代码:

This sounds like a problem with linking. I could compile your code without problems using g++:

g++ Test.cpp -L/path/to/my/openCV/lib -lopencv_core -lopencv_imgcodecs -o Test

如果要使用Open CV的其他功能,则可能必须链接到其他Open CV库.

If you want to use further functions of Open CV you might have to link against additional Open CV libraries.

这篇关于对cv :: imread(cv :: String const&amp ;, int)的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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