0

I need to develop an iOS app with the objective c as base code and to include a CPP library with .so as extension. For that i created a cpp file with a simple program and converted it into .so extension using the following commands given at the link: https://iq.opengenus.org/create-shared-library-in-cpp/

The command which i executed to generate .so file is given as:

// Convert library code to Object file
g++ -c -o library.o library.c

// Create shared .SO library
gcc -shared -o libfoo.so library.o

However if i tried to use this libfoo.so file in xcode it gives me the error built for macOS.**"

How can i build it for iOS simulator and devices?

user16780334
  • 422
  • 5
  • 20
  • note that shared libraries on macos usually use `.dylib` rather than `.so`, you'll need to pass all the relevant command line settings to the compiler to make it build for IOS rather than macOS. Is there a reason you aren't just building with xcode which will do this for you? – Alan Birtles Apr 11 '22 at 10:23
  • @AlanBirtles to be honest i am really new to integrate .so file in objective c . The main point is am stuck is how to generate .so for iOS platform . Because of this i cannot integrate the .so file in my xcode app for a poc. Can you please suggest how building with xcode will generate .so for my iOS platform? – user16780334 Apr 11 '22 at 10:25
  • just add the c file to your xcode app, no real need to create a separate library – Alan Birtles Apr 11 '22 at 10:26
  • then it'll be up to them to build the dylib and you can just include it? Not sure why you're trying to build a library yourself at all? – Alan Birtles Apr 11 '22 at 10:29
  • no, you need to use a dylib, .so files are for linux – Alan Birtles Apr 11 '22 at 10:31
  • @AlanBirtles any links to support this valuable information? – user16780334 Apr 11 '22 at 10:35
  • https://stackoverflow.com/questions/2339679/what-are-the-differences-between-so-and-dylib-on-macos – Alan Birtles Apr 11 '22 at 10:49
  • To generate .dylib library, have you seen? – Tolga Apr 11 '22 at 11:51
  • @Tolga but there is no solution to it right? – user16780334 Apr 11 '22 at 11:52

0 Answers0