Explicitly control link to static library for a dependency?

Hello all! I've been steadily attempting to migrate my Xcode-based macOS app over from Carthage to SPM. Most dependencies were easy, but I'm now on the hard stuff, and I'm having trouble.

I have a non-public swift wrapper around two C libraries. Inside the wrapper package, I've added two systemLibrary target to describe the C libraries I need to build/link against. This was my first struggle, as one of them does not provide a pkg-config file. I found the easiest way to get around this was to just manually create and install one. So far, so good. Though, I'd love to hear another suggestion as to how to do this.

However, I noticed an issue when actually building my app. It turns out that the other C library builds and installs both a .dylib and .a, and also includes a .pc file. Users of my app will not have this lib installed, so my swift wrapper must link against the static library. As far as I can tell, I have no way to control this, unless I either manually tweak the library-supplied pkg-config or delete the dylib.

Am I missing a way to control the linking behavior for a SPM dependency from Xcode? Or perhaps there's another option I'm not aware of? It seems like if I could add some swift flags on a per-package basis from Xcode I might be able to get around both my missing pkg-config and static/dynamic linking issue.

I think that's unfortunately correct. Is it possible for you to ship the dylib as part of your app? If yes, you could embed it there and change rpaths accordingly.

1 Like

I really appreciate the confirmation.

Shipping the dylib is an interesting idea, and definitely one I hadn't thought of. It's fairly easy for me to work around this, but that's definitely an option I'll keep in mind in case this becomes more of an issue. Thanks so much!

Terms of Service

Privacy Policy

Cookie Policy