I have a problem linking OpenCV in Xcode. I installed OpenCV using brew:

brew tap homebrew/science
sudo brew install opencv

I started a new Xcode commandline project, added /usr/local/lib and /usr/local/include to library and header search path. I also added the output of pkg-config --libs opencv to other linker options.

But when I try to compile this small sample program:

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

int main(int argc, char *argv[])
{
    cv::Mat test;
    cv::namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
    cv::waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
} 

i get the following linker error:

Undefined symbols for architecture x86_64:
  "cv::namedWindow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64

But I am able to compile the program on the command line using

g++ `pkg-config --cflags --libs opencv` prog.cpp

So I think the problem is the way Xcode is set up. But I am not able to determine what exactly is different between the way Xcode compiles and my commandline argument.

Does anyone know the reason for this error or has an idea what I could try to investigate the problem?

Edit
Report