title: Undefined symbols for architecture x86_64 error when linking OpenCV in Xcode
body: <p>I have a problem linking OpenCV in Xcode.
  I installed OpenCV using brew:</p>
  
  <pre><code>brew tap homebrew/science
  sudo brew install opencv
  </code></pre>
  
  <p>I started a new Xcode commandline project, added <code>/usr/local/lib</code> and <code>/usr/local/include</code> to library and header search path.
  I also added the output of <code>pkg-config --libs opencv</code> to <code>other linker options</code>.</p>
  
  <p>But when I try to compile this small sample program:</p>
  
  <pre><code>#include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  
  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;
  } 
  </code></pre>
  
  <p>i get the following linker error:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "cv::namedWindow(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, int)", referenced from:
        _main in main.o
  ld: symbol(s) not found for architecture x86_64
  </code></pre>
  
  <p>But I am able to compile the program on the command line using</p>
  
  <pre><code>g++ `pkg-config --cflags --libs opencv` prog.cpp
  </code></pre>
  
  <p>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.</p>
  
  <p>Does anyone know the reason for this error or has an idea what I could try to investigate the problem?</p>