title: How to link a C++ program using OpenCV on MacOS
body: <p>I'm a newbie on openCV.<br>
  I just downloaded the source of openCV from Github and installed it on the desktop (Mac OS).<br></p>
  
  <p>Now I need to do convert a binary file to an image file. Here is the code:<br></p>
  
  <pre><code>// The program is first to convert the image to the binary file then convert the binary file back to the image
  #include &lt;iostream&gt;
  #include &lt;/Users/Me/Desktop/opencv-master/include/opencv2/opencv.hpp&gt;
  #include &lt;/Users/Me/Desktop/opencv-master/modules/highgui/include/opencv2/highgui.hpp&gt;
  
  const std::string filename = "test.dat";
  const std::string picname = "pano_b.jpg";
  
  int main(int argc, char **argv)
  {
      std::ofstream outfile;
      outfile.open(filename.c_str(), std::ios::binary);
      if (!outfile)
      {
          std::cerr &lt;&lt; "failed to open the file : " &lt;&lt; filename &lt;&lt; std::endl;
          return -1;
      }
      cv::Mat srcImg = cv::imread(picname);
      if (srcImg.empty())
      {
          std::cerr &lt;&lt; "failed to open the file : " &lt;&lt; picname &lt;&lt; std::endl;
          return -1;
      }
      for (int r = 0; r &lt; srcImg.rows; r++)
          outfile.write(reinterpret_cast&lt;const char*&gt;(srcImg.ptr(r)), srcImg.cols*srcImg.elemSize());
      std::cout &lt;&lt; "write to file ok!" &lt;&lt; std::endl;
  
      ///// Here the file test.dat is generated. It looks like this:
      ///// 0069 a800 6caa 0074 af0c 80b9 2096 ca2a
      ///// 9fd2 1c8d bf03 71a1 0773 a300 6295 0064
      ///// 9907 73a9 0070 a900 6da8 0480 bc18 95d2
      ///// ...
  
  
  
      //////// Now I want to convert test.dat into an image file
  
      cv::Mat img = cv::imread(filename.c_str(), cv::IMREAD_ANYCOLOR);
      cv::imshow("img", img);
      cv::waitKey();
  
      return 0;
  }
  </code></pre>
  
  <p>However I got an error as below:<br></p>
  
  <blockquote>
    <p>Undefined symbols for architecture x86_64:   "cv::imshow(cv::String
    const&amp;, cv::_InputArray const&amp;)", referenced from:
          _main in bbb-bb77f0.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to
    see invocation)</p>
  </blockquote>
  
  <p>As I said, I installed the openCV on the desktop, here is how I compile:<br></p>
  
  <pre><code>g++ test.cpp /Users/Me/Desktop/opencv-master/build/lib/libopencv_core.dylib /Users/Me/Desktop/opencv-master/build/lib/libopencv_imgproc.dylib /Users/Me/Desktop/opencv-master/build/lib/libopencv_imgcodecs.dylib
  </code></pre>
  
  <p>Here is all lib files that I found in the openCV directory:<br>
  <a href="https://i.stack.imgur.com/quuBB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/quuBB.png" alt="enter image description here"></a></p>
  
  <p>What should I do to solve this link error?</p>