3 ms·
Use dlopen? I haven’t tried this in Go, but if you want a binary that optionally includes features from an external library, you want to use dlopen to load it.
by CGamesPlay 10mo ago
Use dlopen? I haven’t tried this in Go, but if you want a binary that optionally includes features from an external library, you want to use dlopen to load it.
- immibis 10mo agoIt only works in a dynamically-linked binary, because the dynamic linker needs to be loaded.
- CGamesPlay 10mo agoThat makes sense. Some digging turns up some workarounds; the best I found was https://github.com/jart/cosmopolitan/releases/tag/3.1 https://github.com/jart/cosmopolitan/releases/tag/3.1
- immibis 10mo agoYou can write your own dynamic loader, or port the one from libc, or attempt to statically link it (against its wishes). Nothing stops you opening a .so file and mmapping the appropriate sections - that's what the dynamic loader does, and it's just normal user-space code, after all. However, the libc dynamic loader definitely prefers to be your program's entry point. You're swimming against the current by doing it any other way.