title: Xcode 4, dylib & install_name_tool
body: <p>I'm trying to get a dylib working in my OSX project.</p>
  
  <p>Ive been reading a few samples, this one specifically:
  <a href="https://stackoverflow.com/questions/6801709/xcode-4-adding-dylib">Xcode 4 adding dylib</a></p>
  
  <p>But I still cannot get it to work.</p>
  
  <p>Here are the steps I have performed:</p>
  
  <ol>
  <li>Copied the testing.1.dylib to my Xcode projects folder.</li>
  <li>Ran <code>sudo install_name_tool -id @executable_path/../Frameworks/testing.1.dylib testing.1.dylib</code></li>
  <li><p>Ran: <code>otool -L testing.1.dylib</code> and received the following:</p>
  
  <blockquote>
    <p>testing.1.dylib:<br>
        @executable_path/../Frameworks/testing.1.dylib (compatibility version 2.0.0, current version 2.0.0)<br>
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)</p>
  </blockquote></li>
  <li><p>Added the <code>testing.1.dylib</code> as a framework to the project. (Using the link bundle with library option).</p></li>
  <li>At this point when I compile the testing1.dylib does not get copied into the .App/Framework as I expected, so I manually create the Framework path and copy the testing.1.dylib to it:
  a) mkdir -p testing.app/Contents/Frameworks
  b) cp testing.1.dylib testing.app/Contents/Frameworks</li>
  <li>In Xcode I update the <code>Runtime Search Paths</code> for BOTH the Target and the Project to be: @executable_path/../Frameworks.</li>
  </ol>
  
  <p>Now I copy the testing.app to a separate freshly installed machine and attempt to run it. Which I get the following error:</p>
  
  <p>dyld: Library not loaded: /user/local/lib/testing1.dylib
    Referenced from: /Users/me/testing.app/MacOS/./testing
    Reason: image not found</p>
  
  <p>What am I missing?</p>
  
  <p>Notes: When running install_name_tool, I need to use sudo or I get the following errors:</p>
  
  <p>install_name_tool: can't open input file: testing.1.dylib for writing (Permission denied)
  install_name_tool: can't lseek to offset: 0 in file: testing.1.dylib for writing (Bad file descriptor)
  install_name_tool: can't write new headers in file: testing.1.dylib (Bad file descriptor)
  install_name_tool: can't close written on input file: testing.1.dylib (Bad file descriptor)</p>