LLVMLinkModules2() C-API question

Hey all,

A quick question about the LLVM C-Api and using LinkModules. In a normal situation where I have 2 LLVM modules and 1 depends on the other using LLVMLinkModules2() works perfectly.

LLVMLinkModules2() “Links the source module into the destination module. The source module is destroyed.” according to the comment of the function. That is all fine when you only have 2 modules.

But how are you supposed to act in a triangulary dependency like below?


Hi Lefteris,

I’m not sure how _right_ my solution is, but it should work, at least as a workaround.

To prevent a CommonModule from being destroyed you can make a copy of the module. You can do so using LLVMCloneModule method, so that the code may look like this:

let commonModuleForA = LLVMCloneModule(CommonModule)
LLVMLinkModule2(commonModuleForA, ModuleA)

let commonModuleForB = LLVMCloneModule(CommonModule)
LLVMLinkModule2(commonModuleForB, ModuleB)

Hope that will help you.

Best regards,

Hello Alex,

This sounds like a workaround that should do the trick! I will try it out today.

Thank you for the reply.

Best Regards,