<div style="line-height:1.7;color:#000000;font-size:14px;font-family:arial">Yeah, I implemented the check function in another separated file (check.c) and then linked it with hello.o.<br>It turns out that I made a mistake by naming the function "print" in check.c file. It should be named "check" too, so<br>that the programme could find it!<br><br>Thanks for your information!<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><pre><br>At 2012-04-10 21:02:02,"Alexander Potapenko" <glider@google.com> wrote:
>Your files do not appear to implement the check() function.
>
>On Tue, Apr 10, 2012 at 4:57 PM, 15102925731 <zhenkaixd@126.com> wrote:
>> Hi, my friends
>>
>> 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).
>>
>> But when I link the two objective file, it said
>>  "hello.o: In function `main':
>> hello.bc:(.text+0x69): undefined reference to `check'
>> clang: error: linker command failed with exit code 1 (use -v to see
>> invocation)" What's wrong??
>>
>>  To make it readable I convert the .bc file into .ll file using llvm-dis.
>> The IR code is as follow, any help?
>>
>> Before running the pass
>> ; ModuleID = 'hello.bc'
>> 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"
>> target triple = "i386-pc-linux-gnu"
>>
>> @.str = private unnamed_addr constant [18 x i8] c"add result is %d\0A\00",
>> align 1
>> @.str1 = private unnamed_addr constant [20 x i8] c"minus result is
>> %d\0A\00", align 1
>> @str = private unnamed_addr constant [13 x i8] c"hello world!\00"
>>
>> define i32 @add(i32 %a, i32 %b) nounwind readnone {
>> entry:
>>   %add = add nsw i32 %b, %a
>>   ret i32 %add
>> }
>>
>> define i32 @minus(i32 %a, i32 %b) nounwind readnone {
>> entry:
>>   %sub = sub nsw i32 %a, %b
>>   ret i32 %sub
>> }
>>
>> define i32 @main() nounwind {
>> entry:
>>   %call1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18
>> x i8]* @.str, i32 0, i32 0), i32 3) nounwind
>>   %call3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([20
>> x i8]* @.str1, i32 0, i32 0), i32 1) nounwind
>>   %puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str,
>> i32 0, i32 0))
>>   ret i32 0
>> }
>>
>> declare i32 @printf(i8* nocapture, ...) nounwind
>>
>> declare i32 @puts(i8* nocapture) nounwind
>> After running the pass
>> ; ModuleID = 'newhello.bc'
>> 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"
>> target triple = "i386-pc-linux-gnu"
>>
>> @.str = private unnamed_addr constant [18 x i8] c"add result is %d\0A\00",
>> align 1
>> @.str1 = private unnamed_addr constant [20 x i8] c"minus result is
>> %d\0A\00", align 1
>> @str = private unnamed_addr constant [13 x i8] c"hello world!\00"
>>
>> define i32 @add(i32 %a, i32 %b) nounwind readnone {
>> entry:
>>   %add = add nsw i32 %b, %a
>>   ret i32 %add
>> }
>>
>> define i32 @minus(i32 %a, i32 %b) nounwind readnone {
>> entry:
>>   %sub = sub nsw i32 %a, %b
>>   ret i32 %sub
>> }
>>
>> define i32 @main() nounwind {
>> entry:
>>   %call1 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([18
>> x i8]* @.str, i32 0, i32 0), i32 3) nounwind
>>   %call3 = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([20
>> x i8]* @.str1, i32 0, i32 0), i32 1) nounwind
>>   %CallCheck = call i32 @check()
>>   %puts = tail call i32 @puts(i8* getelementptr inbounds ([13 x i8]* @str,
>> i32 0, i32 0))
>>   ret i32 0
>> }
>>
>> declare i32 @printf(i8* nocapture, ...) nounwind
>>
>> declare i32 @puts(i8* nocapture) nounwind
>>
>> declare i32 @check()
>> The original hello.c file
>> #include <stdio.h>
>> extern int check();
>> int add(int a,int b)
>> {
>>     return a+b;
>> }
>>
>> int minus(int a,int b)
>> {
>>     return a-b;
>> }
>> int main()
>> {
>>     int a=2,b=1;
>>     printf("add result is %d\n",add(a,b));
>>     printf("minus result is %d\n",minus(a,b));
>>     printf("hello world!\n");
>>     return 0;
>> }
>> The original check.c file
>> #include <stdio.h>
>> void print()
>> {
>>     printf("Check function works!\n");
>>
>> }
>> --
>>             ×£ºÃ£¡
>>
>>   Õç¿­
>> ------------------------------------------------------------------------------------------------------
>> 2012-04-10
>> ------------------------------------------------------------------------------------------------------
>> Name: Õç¿­(ZhenKai)
>> Homepage:http://www.renren.com/262729393
>> Email: zhenkaixd@126.com or 846227103@qq.com
>> TEL: 15810729006(Beijing)
>> Address: Room I-406, Central Building, Tsinghua University, Beijing, China.
>> 100084.
>>
>> At 2012-04-10 20:00:08,15102925731 <zhenkaixd@126.com> wrote:
>>
>> I did it !!!!
>> YOU MADE MY DAY  !!!!!!!!!!!!!!!
>>
>> --
>>             ×£ºÃ£¡
>>
>>   Õç¿­
>> ------------------------------------------------------------------------------------------------------
>> 2012-04-10
>> ------------------------------------------------------------------------------------------------------
>> Name: Õç¿­(ZhenKai)
>> Homepage:http://www.renren.com/262729393
>> Email: zhenkaixd@126.com or 846227103@qq.com
>> TEL: 15810729006(Beijing)
>> Address: Room I-406, Central Building, Tsinghua University, Beijing, China.
>> 100084.
>>
>>
>> At 2012-04-10 19:55:04,"Duncan Sands" <baldrick@free.fr> 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
>>>LLVMdev@cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev@cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
>
>
>-- 
>Alexander Potapenko
>Software Engineer
>Google Moscow
</pre></div><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>