<div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial">Hi, my friends<br><br>I finally insert the callInst into the hello.bc file.Then I compile the hello.bc to hello.o file and the check.c to check.o file. And I think by link those to .o file togetherI can get the executable ELF file(clang hello.o check.o -o finalfile).<br><br>But when I link the two objective file, it said<br> "hello.o: In function `main':<br>hello.bc:(.text+0x69): undefined reference to `check'<br>clang: error: linker command failed with exit code 1 (use -v to see invocation)" What's wrong??<br><br> To make it readable I convert the .bc file into .ll file using llvm-dis. The IR code is as follow, any help?<br><br><b></b><span style="font-size: 32px;"><b>Before running the pass</b></span><br>; ModuleID = 'hello.bc'<br>target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"<br>target triple = "i386-pc-linux-gnu"<br><br>@.str = private unnamed_addr constant [18 x i8] c"add result is %d\0A\00", align 1<br>@.str1 = private unnamed_addr constant [20 x i8] c"minus result is %d\0A\00", align 1<br>@str = private unnamed_addr constant [13 x i8] c"hello world!\00"<br><br>define i32 @add(i32 %a, i32 %b) nounwind readnone {<br>entry:<br>  %add = add nsw i32 %b, %a<br>  ret i32 %add<br>}<br><br>define i32 @minus(i32 %a, i32 %b) nounwind readnone {<br>entry:<br>  %sub = sub nsw i32 %a, %b<br>  ret i32 %sub<br>}<br><br>define i32 @main() nounwind {<br>entry:<br>  %call1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 x i8]* @.str, i32 0, i32 0), i32 3) nounwind<br>  %call3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([20 x i8]* @.str1, i32 0, i32 0), i32 1) nounwind<br>  %puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str, i32 0, i32 0))<br>  ret i32 0<br>}<br><br>declare i32 @printf(i8* nocapture, ...) nounwind<br><br>declare i32 @puts(i8* nocapture) nounwind<br><b></b><span style="font-size: 32px;"><b>After running the pass</b></span><br>; ModuleID = 'newhello.bc'<br>target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S128"<br>target triple = "i386-pc-linux-gnu"<br><br>@.str = private unnamed_addr constant [18 x i8] c"add result is %d\0A\00", align 1<br>@.str1 = private unnamed_addr constant [20 x i8] c"minus result is %d\0A\00", align 1<br>@str = private unnamed_addr constant [13 x i8] c"hello world!\00"<br><br>define i32 @add(i32 %a, i32 %b) nounwind readnone {<br>entry:<br>  %add = add nsw i32 %b, %a<br>  ret i32 %add<br>}<br><br>define i32 @minus(i32 %a, i32 %b) nounwind readnone {<br>entry:<br>  %sub = sub nsw i32 %a, %b<br>  ret i32 %sub<br>}<br><br>define i32 @main() nounwind {<br>entry:<br>  %call1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18 x i8]* @.str, i32 0, i32 0), i32 3) nounwind<br>  %call3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([20 x i8]* @.str1, i32 0, i32 0), i32 1) nounwind<br><span style="color: rgb(255, 0, 0);">  %CallCheck = call i32 @check()</span><br>  %puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str, i32 0, i32 0))<br>  ret i32 0<br>}<br><br>declare i32 @printf(i8* nocapture, ...) nounwind<br><br>declare i32 @puts(i8* nocapture) nounwind<br><br><span style="color: rgb(255, 0, 0);">declare i32 @check()</span><br><span style="color: rgb(255, 0, 0);"></span><b><span style="color: rgb(0, 0, 0); font-size: 32px;"><span style="color: rgb(0, 0, 0);">The original hello.c file</span></span></b><br>#include <stdio.h><br>extern int check();<br>int add(int a,int b)<br>{<br>    return a+b;<br>}<br><br>int minus(int a,int b)<br>{<br>    return a-b;<br>}<br>int main()<br>{<br>    int a=2,b=1;<br>    printf("add result is %d\n",add(a,b));<br>    printf("minus result is %d\n",minus(a,b));<br>    printf("hello world!\n");<br>    return 0;<br>}<br><b style="font-size: 32px;">The original check.c file</b><br>#include <stdio.h><br>void print()<br>{<br>    printf("Check function works!\n");<br>}<br><div>--<br><div>
<div>
<div><font color="#c0c0c0" size="2">
<div><font color="#c0c0c0"><font size="3">  <span style="COLOR: #000000">          ×£ºÃ£¡</span></font></font></div><span style="COLOR: #000000">
<div> </div>
<div><font size="3">  Õç¿­</font></div>
<div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div></div>
<div><font color="#c0c0c0"><font size="3">2012-04-10</font></font></div></span></font></div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div>
<div><font color="#c0c0c0"><font size="3">Name: Õç¿­(ZhenKai)<br>Homepage:http://www.renren.com/262729393</font></font></div>
<div><font color="#c0c0c0"><font size="3">Email: </font><a href="mailto:zhenkaixd@126.com" target="_blank" _listener="1901"><font color="#0066cc" size="3">zhenkaixd@126.com</font></a><font size="3"> or <a href="mailto:846227103@qq.com">846227103@qq.com</a></font></font></div>
<div><font color="#c0c0c0" size="3">TEL: 15810729006(Beijing)<br>Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.</font></div></div></div></div><div id="divNeteaseMailCard"></div><br>At 2012-04-10 20:00:08,15102925731 <zhenkaixd@126.com> wrote:<br> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial">I did it !!!! <br>YOU MADE MY DAY  !!!!!!!!!!!!!!! <br><br><div>--<br><div>
<div>
<div><font color="#c0c0c0" size="2">
<div><font color="#c0c0c0"><font size="3">  <span style="COLOR: #000000">          ×£ºÃ£¡</span></font></font></div><span style="COLOR: #000000">
<div> </div>
<div><font size="3">  Õç¿­</font></div>
<div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div></div>
<div><font color="#c0c0c0"><font size="3">2012-04-10</font></font></div></span></font></div>
<div><font color="#c0c0c0"><font size="3">------------------------------------------------------------------------------------------------------</font></font></div>
<div><font color="#c0c0c0"><font size="3">Name: Õç¿­(ZhenKai)<br>Homepage:http://www.renren.com/262729393</font></font></div>
<div><font color="#c0c0c0"><font size="3">Email: </font><a href="mailto:zhenkaixd@126.com" target="_blank" _listener="1901"><font color="#0066cc" size="3">zhenkaixd@126.com</font></a><font size="3"> or <a href="mailto:846227103@qq.com">846227103@qq.com</a></font></font></div>
<div><font color="#c0c0c0" size="3">TEL: 15810729006(Beijing)<br>Address: Room I-406, Central Building, Tsinghua University, Beijing, China. 100084.</font></div></div></div></div><div></div><br><pre><br>At 2012-04-10 19:55:04,"Duncan Sands" <<a href="mailto:baldrick@free.fr">baldrick@free.fr</a>> wrote:
>Hi,
>
>> BTW the opt command I use is *"opt -load ../../../Debug+Asserts/lib/Hello.so
>> -hello <hello.bc> -o hello.bc"*
>
>just use hello.bc not <hello.bc> otherwise the shell will redirect input and
>output.
>
>Ciao, Duncan.
>_______________________________________________
>LLVM Developers mailing list
><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         http://llvm.cs.uiuc.edu
>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
</pre></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span></blockquote></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>