1

I have installed OpenCV via homebrew, for my Mac OSX.

The problem I am having is that I am unable to use the imread openCV command at all. 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. However when uncommented, it does not recognize the command.

What is going on here?

Spacey
  • 2,941
  • 10
  • 47
  • 63
  • `g++` is trying to link against an `x86_64` version of the OpenCV libraries, which apparently, you lack. – user703016 Jun 15 '14 at 21:40
  • @WilliamAndrewMontgomery Here's the thing though. If I use other functions of openCV besides 'imread', I get no problem. In fact, if I compile using cmake instead of g++, the code works. So I am trying to figure out how to get it to work via g++ ... – Spacey Jun 15 '14 at 21:42
  • `cmake` is not a compiler and it probably uses `g++` under the hood. Can you take a look at the command line generated by `cmake`? – user703016 Jun 15 '14 at 21:44
  • @WilliamAndrewMontgomery Gladly, but not sure how to do that... I basically followed this tutorial [here](http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html). – Spacey Jun 15 '14 at 21:47
  • Just run `make VERBOSE=1` and look for the commands that gets run – nos Jun 15 '14 at 22:39
  • @nos Thanks nos, hmm, I did that but cannot seem to find any discrepancy... maybe openCV cant be compiled with g++ after all? – Spacey Jun 15 '14 at 22:50
  • @Learnaholic it definitely can be. Maybe you are missing libjpg or cmake picked up the wrong version of it. – QED Jun 16 '14 at 19:01
  • What is output of "echo `pkg-config --libs opencv`" ? – bikz05 Oct 15 '14 at 06:03

1 Answers1

0

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

need LDFLAG of "-lopencv_imgproc".

Community
  • 1
  • 1
sean
  • 51
  • 6