dynamic linking with LLVM
c++, dynamic-linking, llvm
Solution
Try this:
Linker::LinkModules(destinationModule, sourceModule, Linker::PreserveSource, &error);
If you pass `Linker::PreserveSource` instead of `Linker::DestroySource`, you can continue to use `sourceModule` after the call.
Problem
I want to execute functions in a module, this module will have dependencies resolved in other modules. the modules might change (dynamic compilation environment) so i would prefer not not link all the dependencies in a single monolithic module, that is, if it can be avoided I hope to use `Linker::linkModules` but this is always destructive on the source module. That is ok for one module depending on a single one, since if that one changed, is no big deal, but isn't it overkill to rebuild and relink N-1 modules that did not change just because of a single one that changed? I wonder if there is a non-destructive version of linkModules that can work for JIT execution.