<div dir="ltr"><div><div><div>Hello Duncan,<br><br></div>Thank you for your reply. I did figure it out in the end. It was a linkage conflict between the modules. There were some global types that I was declaring in both modules. After removing them, linking worked perfectly.<br><br></div>Still it's a mystery why I got no error string pointing me to the reason the linking failed in the first place.<br><br></div>Best Regards,<br></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><table border="0"><tbody><tr><td style="color:#999999">Lefteris(Eleftherios) Karapetsas</td>
</tr>
<tr>
<td style="color:#999999">Click <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lefteris.refu.co&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ZkU46yFJx8KxEM0l5jcFobRVF1Di7-Si_PXGxy9OYj0&s=yfznjAURU01daIxJMyU9o3y9UuCmrJv4eQLdyzZaXR4&e=" target="_blank">here</a> for my CV/portfolio website<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__lefteris.refu.co&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ZkU46yFJx8KxEM0l5jcFobRVF1Di7-Si_PXGxy9OYj0&s=yfznjAURU01daIxJMyU9o3y9UuCmrJv4eQLdyzZaXR4&e=" target="_blank"><br></a></td>
</tr>
<tr>
<td style="color:#999999"></td>
</tr>
<tr>
<td style="color:#999999">Also maintain a <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__blog.refu.co&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=Mfk2qtn1LTDThVkh6-oGglNfMADXfJdty4_bhmuhMHA&m=ZkU46yFJx8KxEM0l5jcFobRVF1Di7-Si_PXGxy9OYj0&s=YurFGGPxswVOVZTaYM3NPZmx5gSt4hXzbpuabZuqIoo&e=" target="_blank">blog </a>on various topics, mostly
engineering<br></td>
</tr>
<tr>
<td style="color:#999999"><br></td></tr></tbody></table></div></div></div>
<br><div class="gmail_quote">On Thu, Jun 11, 2015 at 6:41 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
> On 2015-Jun-08, at 07:11, Lefteris Karapetsas <<a href="mailto:lefteris@refu.co">lefteris@refu.co</a>> wrote:<br>
><br>
> Hello all,<br>
><br>
> I am using llvm as a backend to a hobby language I am making. I have experimented with the C bindings since the project is written in C. I had no problems building a single lllvm module so far. I am not using a JIT compiler but at least at the moment am simply generating executables. The workflow I am using is to build a module with LLVMModuleCreateWithName() and populate it with the LLVMBuilder.<br>
><br>
> After everything is in the module I simply output it into a file with LLVMPrintModuleToFile(). Then I am calling llc to convert the IR to native machine code and finally gcc to create an executable out of it. All these from inside my program. It may not be the best way to generate an executable and I would really welcome as much advice as you can give me on that but it works.<br>
><br>
> The issue comes when I actually create 2 different modules. One being a "standard" library of sorts and the other the main module which should use it. I create both modules, with no errors appearing if I use LLVMVerifyModule() on them.<br>
><br>
> The problem is how do I link them? I tried to do it like this:<br>
><br>
> // if an error occurs LLVMLinkModules() returns true<br>
> if (true == LLVMLinkModules(main_module, stdlib_module, LLVMLinkerDestroySource, &error)) {<br>
> bllvm_error("Could not link LLVM modules", error);<br>
> goto end;<br>
> }<br>
><br>
><br>
> But this fails (returns true), with no error. Even though both modules are valid. I understand that the above may be a really naive mistake, and that my whole approach may be wrong. This is why I would appreciate any links to tutorials/documents which would show the proper way to link 2 modules or some good old simple advice tips from any of you guys.<br>
<br>
</div></div>Weird that you're not getting an error message.<br>
<br>
Best thing is probably to spin up a debugger (or add some printfs)<br>
and see what's going on.<br>
<br>
One hypothetical point of failure: module linking requires that both<br>
modules are in the same context. If that's not the problem (and it<br>
probably isn't, since I'd expect crashes there), my bet would be on<br>
some sort of linkage conflict between the modules.</blockquote></div><br></div>