Dynamic Linking within a Single Package

Is there a way to make a package target depend on a dynamic library product in the same package?

It doesn’t seem to be able to find the products in the same package, even when declared explicitly: .productItem(name: "LibraryProduct", package: "ThisPackage").

Depending on the corresponding targets instead compiles fine, but then nothing is linked dynamically.

What I want to do is have two executables share code in a library, and have all three in one package, thereby reducing the binary size of the two executables. Right now though, adding the library product just causes its content to duplicated an additional time, bringing it to three copies of the same binary content.

Did you find out any way to do this?

No. It is still not possible.

1 Like

In my project delta-client I have worked around this by putting the targets to dynamically link against into a nested package, and then I have a 'shim' target that reexports the targets which are in the nested package so that people using my package can still access the targets that are in the nested package.