I don't have any prior experience with swift.
I have a static library libseriallib.a
which was written in C++ but has a C wrapper interface by using extern C
.
I want to link this library into a swift iOS application. I am creating this application from scratch.
There are three libraries that libseriallib.a
depends on. These are: libz.a
, 'libcrypto.a,
libssh.a`.
I followed the second method mentioned here (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 libseriallib.a
to XCode Build Phases->Link Binary With Libraries
section.
The errors I have right now look like this:
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<true>::__throw_length_error() const", referenced from:
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
"std::__1::ios_base::getloc() const", referenced from:
"std::runtime_error::runtime_error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
Now, it looks like I have to link libstd++
also.
Is there any comprehensive resource to how to link a C/C++ library with a swift iOS app?
Any help would be much appreciated.