<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>I have a question concerning llvm-c.</div><div>I have set up a function that needs to invoke an external method, in a other library. It has the following signature: void* NSFullUserName(void);</div><div>The void* can be replaced with a i8*, that far I was able to get, but when my call is invoked, the engine gives me the following message:</div><div><font class="Apple-style-span" face="Menlo" size="3"><span class="Apple-style-span" style="font-size: 11px; "><b><font class="Apple-style-span" face="Helvetica"><span class="Apple-style-span" style="font-weight: normal; font-size: medium; "><br></span></font></b></span></font></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; "><b>LLVM ERROR: Tried to execute an unknown external function: i8* ()* NSFullUserName</b></div></div><div><br></div><div>I have dumped the module (without the clutter):</div><div><br></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; "><b>declare i8* @NSFullUserName()</b></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; min-height: 13px; "><b></b><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; "><b>define i8* @MyFunction() {</b></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; "><b>entrypoint:</b></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "><b>  %myCall = call i8* @NSFullUserName()            ; <i8*> [#uses=1]</b></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 42px; text-indent: -42px; font: normal normal normal 11px/normal Menlo; "><b>  ret i8* %myCall</b></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 28px; text-indent: -28px; font: normal normal normal 11px/normal Menlo; "><b>}</b></div></div><div><br></div><div>Where am I going wrong here?</div><div><br></div><div>To add some code to my previous question:<div><br></div><div>LLVMTypeRef i8Ptr(void) {<br>    return LLVMPointerType(LLVMInt8Type(), 0);<br>}<br><br>LLVMValueRef d(LLVMModuleRef module) {<br>    LLVMValueRef result;<br>    LLVMBasicBlockRef block;<br>    LLVMBuilderRef builder = LLVMCreateBuilder();<br>    <br>    LLVMValueRef fullUsername = LLVMAddFunction(module, "NSFullUserName", LLVMFunctionType(LLVMPointerType(LLVMInt8Type(), 0), NULL, 0, 0));<br>    LLVMSetLinkage(fullUsername, LLVMExternalLinkage);<br>    <br>    result = LLVMAddFunction(module, "MyFunction", LLVMFunctionType(i8Ptr(), NULL, 0, 0));<br>    block = LLVMAppendBasicBlock(result, "entrypoint");<br>    LLVMPositionBuilderAtEnd(builder, block);<br>    <br>    LLVMValueRef returnVal = LLVMBuildCall(builder, fullUsername, NULL, 0, "myCall");<br>    LLVMBuildRet(builder, returnVal);<br>    <br>    LLVMDisposeBuilder(builder);<br>    return result;<br>}<br><br><br>int main (int argc, const char * argv[]) {<br>    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];<br>    <br>    char * error = NULL;<br>    LLVMExecutionEngineRef engine;<br>    LLVMModuleRef module = LLVMModuleCreateWithName("MyModule");<br>    <br>    LLVMValueRef toCall = d(module);<br>    <br>    LLVMDumpModule(module);<br>    <br>    LLVMLinkInInterpreter();<br>    LLVMCreateInterpreterForModule(&engine, module, &error);<br>    <br>    LLVMGenericValueRef result = LLVMRunFunction(engine, toCall, 0, NULL);<br>    <br>    LLVMDisposeModule(module);<br>    [pool drain];<br>    return 0;<br>}</div><div><br></div><div><br></div><div>Thank you,</div><div><br></div><div>Filip</div></div></body></html>