Search code examples
iosxcodeshared-objectsdynamic-library

iOS - How to use existing dynamic library (.so file)


I have an existing dynamic library, and I try to use this library into my iOS app using dlopen(), but the function always return NULL. The library is a .so file and comes from an Android project. dlerror() return :

dlopen(/var/mobile/Applications/990CF1A9-B467-471B-9FDB-D0929D90B01D/Documents/libsamlib.so, 10): no suitable image found.  
Did find: /var/mobile/Applications/990CF1A9-B467-471B-9FDB-D0929D90B01D/Documents/libsamlib.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00

My app won't be on the App Store, but I read on Internet that load an dynamic library is technically possible. Did someone already managed to load a .so dynamic library with dlopen?


Solution

  • Apparently, the dynamic library that I wanted to imported has to be compiled with the iOS architecture. So, the solution I have found was to re-compiled all source files from the originally library, create a .dylib and dlopen() will work. This link helped me a lot.