title: Linking libraries OpenCV 2.4.2 on xcode 4.5.1
body: <p>I have installed opencv with macports following the directions here: <a href="https://stackoverflow.com/questions/8552839/compile-opencv-2-3-1-for-os-x-lion-mountain-lion-with-xcode">Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode</a></p>
  
  <p>I have also search and tried every other variation of this on stackexchange and google, but this seems to get me closest.</p>
  
  <p>It seems to work for some things, but not for sample code that ships with 2.4.2.  Note that I have added ALL opencv 2.4.2 dylibs Link Binary with Libraries.</p>
  
  <p>For example, the following will compile and run:</p>
  
  <pre><code>#include &lt;opencv2/opencv.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  
  int main ( int argc, char **argv )
  {
      cvNamedWindow( "My Window", 1 );
      IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
      CvFont font;
      double hScale = 1.0;
      double vScale = 1.0;
      int lineWidth = 1;
      cvInitFont( &amp;font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
             hScale, vScale, 0, lineWidth );
      cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &amp;font,
            cvScalar( 255, 255, 0 ) );
      cvShowImage( "My Window", img );
      cvWaitKey();
      return 0;
  }
  </code></pre>
  
  <p>However, when I try to build any of the samples, such as the display_image.cpp, example, as follows, I get link errors.</p>
  
  <p>-DOES NOT WORK-</p>
  
  <pre><code> #include &lt;stdio.h&gt;
   #include &lt;iostream&gt;
   #include "opencv2/imgproc/imgproc.hpp"
   #include "opencv2/highgui/highgui.hpp"
   #include "opencv2/flann/miniflann.hpp"
  
   using namespace cv; // all the new API is put into "cv" namespace. Export its content
   using namespace std;
   using namespace cv::flann;
  
  static void help()
  {
      cout &lt;&lt;
      "\nThis program shows how to use cv::Mat and IplImages converting back and forth.\n"
      "It shows reading of images, converting to planes and merging back, color conversion\n"
      "and also iterating through pixels.\n"
      "Call:\n"
      "./image [image-name Default: lena.jpg]\n" &lt;&lt; endl;
  }
  
  int main(int argc, char *argv[])
  {
      help();
      const char* imagename = argc &gt; 1 ? argv[1] : "lena.jpg";
      Mat img = imread(imagename); // the newer cvLoadImage alternative, MATLAB-style function
      if(img.empty())
      {
          fprintf(stderr, "Can not load image %s\n", imagename);
          return -1;
      }
      if( !img.data ) // check if the image has been loaded properly
          return -1;
  
      Mat img_yuv;
      cvtColor(img, img_yuv, CV_BGR2YCrCb); // convert image to YUV color space. The output image will be created automatically
  
      vector&lt;Mat&gt; planes; // Vector is template vector class, similar to STL's vector. It can store matrices too.
      split(img_yuv, planes); // split the image into separate color planes
  
      imshow("image with grain", img);
  
      waitKey();
  
      return 0;
  
  }
  </code></pre>
  
  <hr>
  
  <p>I get the following errors:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
   "cv::split(cv::Mat const&amp;, std::__1::vector&lt;cv::Mat, std::__1::allocator&lt;cv::Mat&gt; &gt;&amp;)", referenced from:
    _main in main1.o
   "cv::imread(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 main1.o
   "cv::imshow(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;, cv::_InputArray const&amp;)", referenced from:
    _main in main1.o
   ld: symbol(s) not found for architecture x86_64
   clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>Any idea how to resolve this?</p>