0

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.

Eduard
  • 191
  • 10
  • Does this answer your question? [dyld: Library not loaded: ..... How to correctly tell GCC Compiler where to find another static library?](https://stackoverflow.com/questions/66268814/dyld-library-not-loaded-how-to-correctly-tell-gcc-compiler-where-to-find) – Siguza Feb 14 '23 at 15:32
  • @Siguza not really, because your answer contains `.c` headers, and I got a `.h` headers. I can't find a way to implement those commands for my type of headers. I will update my answer to show how they look like. – Eduard Feb 14 '23 at 19:05
  • Neither `.c` nor `.h` files matter for this, and editing them won't change anything. I just needed something to demonstrate things on. What really matters is the install name used in the `LC_ID_DYLIB` command of your dylib and in `LC_LOAD_DYLIB` in everything that links against it. – Siguza Feb 15 '23 at 00:16

0 Answers0