<div dir="ltr">The answer to such questions is usually best obtained by looking at what clang does. See below.<div><div><br></div><div><font face="Monaco"><span style="font-size:9px">$ cat foo.c</span></font></div><div><p style="margin:0px;font-size:9px;font-family:Monaco">#include <stdlib.h></p>
<p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px">void* foo(int i){return malloc(i);}<br></p><p style="margin:0px;font-size:9px;font-family:Monaco">$ clang -emit-llvm -S foo.c</p><p style="margin:0px;font-size:9px;font-family:Monaco">$ cat foo.ll</p><p style="margin:0px;font-size:9px;font-family:Monaco">; ModuleID = 'foo.c'</p><p style="margin:0px;font-size:9px;font-family:Monaco">target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"</p><p style="margin:0px;font-size:9px;font-family:Monaco">target triple = "x86_64-apple-macosx10.10.0"</p><p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px"><br></p><p style="margin:0px;font-size:9px;font-family:Monaco">; Function Attrs: nounwind ssp uwtable</p><p style="margin:0px;font-size:9px;font-family:Monaco">define i8* @foo(i32 %i) #0 {</p><p style="margin:0px;font-size:9px;font-family:Monaco">  %1 = alloca i32, align 4</p><p style="margin:0px;font-size:9px;font-family:Monaco">  store i32 %i, i32* %1, align 4</p><p style="margin:0px;font-size:9px;font-family:Monaco">  %2 = load i32* %1, align 4</p><p style="margin:0px;font-size:9px;font-family:Monaco">  %3 = sext i32 %2 to i64</p><p style="margin:0px;font-size:9px;font-family:Monaco">  %4 = call i8* @malloc(i64 %3)</p><p style="margin:0px;font-size:9px;font-family:Monaco">  ret i8* %4</p><p style="margin:0px;font-size:9px;font-family:Monaco">}</p><p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px"><br></p><p style="margin:0px;font-size:9px;font-family:Monaco">declare i8* @malloc(i64) #1</p><p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px"><br></p><p style="margin:0px;font-size:9px;font-family:Monaco">attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }</p><p style="margin:0px;font-size:9px;font-family:Monaco">attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }</p><p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px"><br></p><p style="margin:0px;font-size:9px;font-family:Monaco">!llvm.ident = !{!0}</p><p style="margin:0px;font-size:9px;font-family:Monaco;min-height:12px"><br></p><p style="margin:0px;font-size:9px;font-family:Monaco">




















</p><p style="margin:0px;font-size:9px;font-family:Monaco">!0 = metadata !{metadata !"Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)"}</p><div><br></div><p style="margin:0px;font-size:9px;font-family:Monaco"><br></p></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 3, 2015 at 4:03 PM, AllenShow via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, everyone.<br>
I am new to llvm and I want to use C function “malloc" and “free" to do heap allocation, but It seems it is not a built-in function like ‘’printf” so I got an error “Unknown extern function”.<br>
I use ExecutionEngineer to run my main function and how should I do to make EE link the C library I want.<br>
Thanks.<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div>