简体   繁体   English

为什么我不能使用g ++编译此OpenCV“ hello world”?

[英]Why cant I compile this OpenCV 'hello world' using g++?

I have installed OpenCV via homebrew, for my Mac OSX. 我已经通过自制软件为Mac OSX安装了OpenCV。

The problem I am having is that I am unable to use the imread openCV command at all. 我遇到的问题是我imread无法使用imread openCV命令。 When I do, I get an error. 当我这样做时,我会得到一个错误。 Here is a breakdown of what I have done. 这是我所做的细目。

My simple code is: 我的简单代码是:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

int main()
{

    Mat imageMe = imread("frog.jpg", 0);
    return 0;
}

To compile, I type this into the command prompt: 要进行编译,我将其输入命令提示符:

  g++ opencvEntry.cpp -o opencvEntry `pkg-config --cflags --libs opencv` && ./opencvEntry

Upon doing that, the error message I get is: 这样做之后,我得到的错误消息是:

Undefined symbols for architecture x86_64:
      "cv::imread(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
          _main in ccvT5f6R.o
    ld: symbol(s) not found for architecture x86_64
    collect2: error: ld returned 1 exit status

So... I am not sure where/what is going on here. 所以...我不确定这是怎么回事。 If I simply uncomment the imread line the file compiles just fine. 如果我只是取消注释未imread行,文件编译就可以了。 However when uncommented, it does not recognize the command. 但是,如果不加注释,它将无法识别该命令。

What is going on here? 这里发生了什么?

I have the same issue, after searching, this is a solution which works for me, hope it can help you as well. 搜索后,我遇到了同样的问题,这是一个对我有用的解决方案,希望它也能对您有所帮助。

Compiling OpenCV code on a 64-bit mac 在64位Mac上编译OpenCV代码

need LDFLAG of "-lopencv_imgproc". 需要“ -lopencv_imgproc”的LDFLAG。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM