0
votes

I want to import a library from native C source code to be used Unity, for iOs. I expect to require the .a binaries and the .h header (and any other file required if I'm missing any), but I cannot find any guide around about how to build it.

I tried to build the source code directly on Xcode, but I was not able to create a library from that. XCode accepts native C only with command line project, while I need a library.

Then I tried to run this CMake command on mac terminal: cmake . -DCMAKE_SYSTEM_NAME=iOS "-DCMAKE_OSX_ARCHITECTURES=arm64;arm64e" -DCMAKE_OSX_DEPLOYMENT_TARGET=9.3 -DENET_STATIC=1 -DENET_LZ4=1 -GXcode

This creates an Xcode project, I build it for generic IOS but the code does not work on unity when I deploy it on the device.

1

1 Answers

1
votes

A good place to start is the Bonjour example from the Unity Manual. This at least gives you a working iOS plugin as a starting point.

You include the files in your Unity project, and build for iOS. You will notice that the files under Plugins/iOS are automatically included in the generated Xcode project. They will only be compiled when you build/run your Xcode project.

Careful, an iOS plugin is not the same as a MacOS plugin. For a MacOS plugin, you will need to create the bundle and include this into your UnityProject. The DllImport decorator will also be different on your C# code. For iOS it is "__Internal", but for MacOS it is the name of the bundle.

If you are trying to interface with a third party library, you may need to manually modify the library search paths of your Xcode project to correctly locate your .a and .h files when building and linking.

As a side note, when including a third party .a binary, verify that it conforms to the iOS architecture requirements, otherwise your app may be rejected when submitting to the app-store.