After much much tweaking and testing. I finally called the C function from another place inside the library and this did work. It's only when called from the dylib that it fails. The symbol _say_hello_world was being stripped from the binary's symbol table during the release build. The function code existed in the binary (verified via dSYM), but Xcode's default Strip Style = All Symbols removes symbol names from the export table. Since dlsym() looks up symbols by name, it couldn't find the function. In the app's Xcode project (not Package.swift): Build Settings → Strip Style → Non-Global Symbols This preserves global symbols (like _say_hello_world) in the binary's symbol table while still stripping local/debug symbols. Limitation This setting cannot be controlled from Package.swift. SPM package authors must document that users need to set STRIP_STYLE = non-global in their app's build settings when using dlsym() with statically linked code. Basically, this is a dead end trying to kee
Topic:
Programming Languages
SubTopic:
General
Tags: