title: Swift link and build with C/C++ library
body: <p>I don't have any prior experience with swift.</p>
  
  <p>I have a static library <code>libseriallib.a</code> which was written in C++ but has a C wrapper interface by using <code>extern C</code>.</p>
  
  <p>I want to link this library into a swift iOS application. I am creating this application from scratch. </p>
  
  <p>There are three libraries that <code>libseriallib.a</code> depends on. These are: <code>libz.a</code>, 'libcrypto.a<code>,</code>libssh.a`.</p>
  
  <p>I followed the second method mentioned <a href="https://spin.atomicobject.com/2015/02/23/c-libraries-swift/" rel="nofollow noreferrer">here</a> (Using module) and tried to build the project. However, I am confused how to link the three dependencies and get it building successfully. Right now I only added <code>libseriallib.a</code> to XCode <code>Build Phases-&gt;Link Binary With Libraries</code> section.</p>
  
  <p>The errors I have right now look like this:</p>
  
  <pre><code>Apple Mach-O Linker Warning Group
  ld: warning: URGENT: building for iOS simulator, but linking in object file (/Users/duminda/dev/swiftlibtest/libseriallib.a(seriallib.cpp.o)) built for OSX. Note: This will be an error in the future.
  
  ld: warning: object file (/Users/duminda/dev/swiftlibtest/libseriallib.a(seriallib.cpp.o)) was built for newer OSX version (10.11) than being linked (10.0)
  
  ld: warning: URGENT: building for iOS simulator, but linking in object file (/Users/duminda/dev/swiftlibtest/libseriallib.a(mem_buffer.cpp.o)) built for OSX. Note: This will be an error in the future.
  
  ld: warning: object file (/Users/duminda/dev/swiftlibtest/libseriallib.a(mem_buffer.cpp.o)) was built for newer OSX version (10.11) than being linked (10.0)
  
  ld: warning: URGENT: building for iOS simulator, but linking in object file (/Users/duminda/dev/swiftlibtest/libseriallib.a(buffers.cpp.o)) built for OSX. Note: This will be an error in the future.
  
  ld: warning: object file (/Users/duminda/dev/swiftlibtest/libseriallib.a(buffers.cpp.o)) was built for newer OSX version (10.11) than being linked (10.0)
  
  ld: warning: URGENT: building for iOS simulator, but linking in object file (/Users/duminda/dev/swiftlibtest/libseriallib.a(packet_reader2.cpp.o)) built for OSX. Note: This will be an error in the future.
  
  ld: warning: object file (/Users/duminda/dev/swiftlibtest/libseriallib.a(packet_reader2.cpp.o)) was built for newer OSX version (10.11) than being linked (10.0)
  
  Apple Mach-O Linker Error Group
    "std::runtime_error::what() const", referenced from:
  
    "std::__1::__basic_string_common&lt;true&gt;::__throw_length_error() const", referenced from:
  
    "std::__1::locale::use_facet(std::__1::locale::id&amp;) const", referenced from:
  
    "std::__1::ios_base::getloc() const", referenced from:
  
    "std::runtime_error::runtime_error(std::__1::basic_string&lt;char, std::__1::char_traits&lt;char&gt;, std::__1::allocator&lt;char&gt; &gt; const&amp;)", referenced from:
  </code></pre>
  
  <p>Now, it looks like I have to link <code>libstd++</code> also.</p>
  
  <p>Is there any comprehensive resource to how to link a C/C++ library with a swift iOS app?</p>
  
  <p>Any help would be much appreciated.</p>