I need to integrate a .dylib
library and .h
headers into iOS project to call its methods from Swift. It's illegal to add a .dylib
file in iOS project, so I've tried to make a few workarounds:
- Create a
.xcframework
with embedded.dylib
and it's headers - Create a
.framework
with with embedded library binary, created using lipo command
Both workarounds compile successfully, but crashes when trying to run on a real device with message:
dyld[38413]: Library not loaded: @rpath/somelib.dylib
Referenced from: <6519D385-F3EB-3454-8CA0-02BF7E536629> /private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/TestApp
Reason: tried: '/usr/lib/system/introspection/somelib.dylib' (errno=2, not in dyld cache), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/preboot/Cryptexes/OS@rpath/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/private/var/containers/Bundle/Application/D1A6139C-EC53-46DA-A647-4A520E4F112C/TestApp.app/Frameworks/somelib.dylib' (errno=2), '/usr/local/lib/somelib.dylib' (errno=2), '/usr/lib/somelib.dylib' (errno=2, not in dyld cache)
My guess is that some paths are setted up incorrectly, but I don't know how to fix that.
Here's content of my .h
headers file:
#ifdef __cplusplus
extern "C" {
#endif
void ms_init(int width, int height);
void ms_draw();
#ifdef __cplusplus
}
#endif
I found a great answer to almost the same question, but the difference is that I use a .h
headers.