Integrate .net dll vs cpp libraries into Xcode project

Hi, I need to integrate either a .NET dll or a CPP library. in an XCode project that targets macOS and iOS. I don't have access to the library's source code. I'm wondering what would be easier (if it's even possible)?

Another option would be to be a cli app that communicates with the macOS/iOS app, but again should I use .Net or cpp?

thanks in advance

This is probably best answered elsewhere since it doesn't have anything to do with open-source Swift.

Given that, Windows .dll files are not useable on Apple systems, they have no meaning other that as a binary blob. Similarly, if the CPP library is a Windows .lib file, it also won't work on Apple systems, it's just a binary blob that the Apple linkers do not understand. If the code has been compiled for Apple systems (.NET dll is actually a dylib, the CPP library is an object file archive, .a file), then all you have to do is add then as libraries to be linked for the Xcode target you want.

1 Like

You’ll need to write shims in plain C to work with either of these libraries. It’ll likely be easier to do that on top of the C++ library, although I believe .Net includes marshalling functionality to interoperate with C so theoretically there should be a way to use that too.

To do this, you’ll need to set up a C language target in your Swift package. The official documentation could use some improvement here, but if you Google for “SwiftPM C target”, you should find some relatively-recent tutorials. Essentially it involves declaring the target and putting the public headers where SwiftPM can find them.

Using a binary library isn’t a problem; you just need to tell the linker where to find it. There are 2 ways to do that:

  1. Use a custom modulemap (this might only apply to system libraries, I’m not sure)
  2. Add custom linker settings in your SwiftPM package manifest

Apologies that I can’t tell you exactly what you need to do to make this work, but hopefully this helps guide you to finding a solution.