title: How can I link executable with dylib in Mac OS X command line?
body: <p>I'm trying to figure out how to compile things on command line without a and ide. This is my first time building a project using command line. And, I get stomped on linking dependencies on a simple project.</p>
  
  <p>I have this tree structure:</p>
  
  <pre><code>.
  ├── include
  ...
  ...
  ├── lib
  │   ├── libopencv_calib3d.3.3.1.dylib
  │   ├── libopencv_core.3.3.1.dylib
  │   ├── libopencv_cudev.3.3.1.dylib
  │   ├── libopencv_features2d.3.3.1.dylib
  │   ├── libopencv_flann.3.3.1.dylib
  │   ├── libopencv_highgui.3.3.1.dylib
  │   ├── libopencv_imgcodecs.3.3.1.dylib
  │   ├── libopencv_imgproc.3.3.1.dylib
  │   ├── libopencv_videoio.3.3.1.dylib
  │   ├── libopencv_ximgproc.3.3.1\ 2.dylib
  │   └── libopencv_ximgproc.3.3.1.dylib
  ├── resources
  │   ├── giraffe.jpg
  │   ├── golden-retriver-puppy.jpg
  │   ├── kangaroo.jpg
  │   └── kitty.jpeg
  └── sources
      └── main.cpp
  </code></pre>
  
  <p>and I have this code in the main:</p>
  
  <pre><code>#include "opencv2/ximgproc/segmentation.hpp"
  #include "opencv2/highgui.hpp"
  #include "opencv2/core.hpp"
  #include "opencv2/imgproc.hpp"
  #include &lt;iostream&gt;
  #include &lt;ctime&gt;
  
  static void help() {
      std::cout &lt;&lt; std::endl &lt;&lt;
      "Usage:" &lt;&lt; std::endl &lt;&lt;
      "./ssearch input_image (f|q)" &lt;&lt; std::endl &lt;&lt;
      "f=fast, q=quality" &lt;&lt; std::endl &lt;&lt;
      "Use l to display less rects, m to display more rects, q to quit" &lt;&lt; std::endl;
  }
  
  
  int main(int argc, char** argv) {
      std::cout &lt;&lt; "Test" &lt;&lt; std::endl;
      // If image path and f/q is not passed as command
      // line arguments, quit and display help message
      if (argc &lt; 3) {
          help();
          return -1;
      }
  
      return 0;
  }
  </code></pre>
  
  <p>and in my mac terminal I built it with this command:</p>
  
  <pre><code>clang++ sources/main.cpp -o a -I./include -L./lib -lopencv_core.3.3.1 -lopencv_ximgproc.3.3.1 -lopencv_highgui.3.3.1 -lopencv_imgproc.3.3.1 -lopencv_imgcodecs.3.3.1
  </code></pre>
  
  <p>and it doesn't give me any errors.</p>
  
  <p>but when I run <code>~$ ./a</code> </p>
  
  <p>I get the following error:</p>
  
  <pre><code>dyld: Library not loaded: @rpath/libopencv_core.3.3.dylib
    Referenced from: 
    /Users/lgdelacruz/Documents/GSoC/project/objectdetection/./a
    Reason: image not found
  Abort trap: 6
  </code></pre>
  
  <p>I've been messing with these for days, and I can't seem to figure it out. How does the executable find the things to link to when it needs those definitions? </p>