Is it possible to load an SPM framework/dylib at runtime under Linux

I can use Bundle on macOS to load a framework at runtime, and that works reasonably well even with Swift (given the principal class is @objc). Can I do something similar under Linux?

A similar question has been posted quite a while ago without any answer (How do you dynamically load a module on Linux?)

Given that Swift has advanced quite a bit, is this possible now?

Can I load a framework/dylib under linux at runtime and use it? Bundle seems to be mostly unimplemented in corelibs foundation.

It is definitely possible to load dylib in linux using swift, I made a little example app couple months ago to document a bug in SPM. You can see implementation here:

there are two related projects, one that defines plugin's interface and other that show how actual plugin is implemented:

Not sure if this is exactly what you need, but it is possible to load your own dylib and interface with it


Ok the problem here is that only C functions can be called, and Swift libraries are not really supported.

I guess my question is if there is any kind of story or roadmap on how and when this is planned to be properly supported (not just on Linux). I mean even on macOS the requirement to only use Obj-C protocols leaves a lot to be desired.

Anyone? @Tony_Parker?

1 Like

I think we can start with a JIRA, for the Linux bit.

This may depend on ABI and module stability; otherwise loading some bit of Swift code that was not compiled with the rest of your code may result in some strange behavior.


Thank you Tony for your answer. Makes sense that it is tied to ABI stability. I can't wait though when Swift on Linux is fully usable™

Should I file the issue on Jira? I guess you are a lot better at wording it though :wink:

1 Like

Maybe @Aciid knows something about this :slight_smile:?

1 Like

Please feel free to create one yourself, and put a link here. Thanks!

I created [SR-7494] Allow loading SPM frameworks at runtime and calling Swift functions on them · Issue #50037 · apple/swift · GitHub

Please feel free to fix terminology mistakes. I have no CS ed after all.

Thank you for your kind support.