title: Xcode linking against static and dynamic library
body: <p>I have some problems with linking my macOS app against C libraries. 
  I have several question related to this issue. </p>
  
  <ol>
  <li><p>It is better to link app against dynamic or static libraries taking into account that this will be very custom libraries rather not shared with other apps?</p></li>
  <li><p>I have linked my macOS Xcode app against ~14 static libraries .a and it works fine. I have reconfigured CMakeLists.txt making this libraries and now Xcode project doesn't work. The main change was changing the directory I have </p></li>
  </ol>
  
  <p><code>"$(SRCROOT)/../../c/&lt;project_name&gt;/outputs/lib/apple/static"</code></p>
  
  <p>But now I have both static (.a) and dynamic (.dylib) libraries in the same path 
      <code>"$(SRCROOT)/../../c/server/outputs/lib/apple"</code></p>
  
  <p>I don't know whether this should matter, but linking against static libraries causes that after running my Xcode project it complains that it cannot load <strong>lib.dylib</strong> So maybe it finds this dynamic library under Library Search Paths and tires to load them but don't find them linked?</p>
  
  <p><a href="https://i.stack.imgur.com/4SyMk.png" rel="noreferrer"><img src="https://i.stack.imgur.com/4SyMk.png" alt="enter image description here"></a></p>
  
  <ol start="3">
  <li>So I tired to link Xcode macOS app against .dylib libraries and instead of static .a libraries added them in Link Binary with Libraries. The problem is that the error not finding library now also occurs.</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/jfpzF.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jfpzF.png" alt="enter image description here"></a></p>
  
  <p>Maybe I should change something here ? But what If I will distribute my app to some other computers that will not have libraries in this specific location. How can I include dynamic libraries in Xcode bundle in order to be always findable. </p>
  
  <p><a href="https://i.stack.imgur.com/jXn27.png" rel="noreferrer"><img src="https://i.stack.imgur.com/jXn27.png" alt="enter image description here"></a></p>
  
  <p>I know I added maybe to many question. But would like to know how to the best solve this issue? Better to link statically or dynamically and then how to correctly achieve this avoiding this error. </p>
  
  <p><strong>UPDATE</strong></p>
  
  <ol>
  <li>It seems that when linking against <code>.dylib</code> it only works when I add path to this library directory to <code>Runpath Search Paths</code>. </li>
  <li>It also seems that when I link against static library <code>.a</code> it works when <code>.dylib</code> isn't in the same directory (I moved <code>.a</code> library into <code>/static</code> subdirectory) and then for this moved library error isn't showing any more. But isn't there way to link statically when there is <strong>.a</strong> and <strong>.dylib</strong> libraries inside the same directory? </li>
  </ol>