how to use external function?

Hi there,

It will be appreciated if you help me :

I need to call an external function in LLVM bitcode but don’t know how :

;ModuleID = ‘m1’
define i32 @main() {
entry:
%tmp0 = call i32 @MyOwnFunction()
ret i32 0
}
declare i32 @MyOwnFunction()

I use below codes to run it

$ llvm-as -f m1 -o m1.bc
$ lli 1.bc

(before it I have compiled MyOwnFunction module)

when I run this program i receive this error :
LLVM ERROR: Program used external function ‘MyOwnFunction’ which could not be resolved!

I know it can not find this external function but I don’t know how to define this function in another module and use it in my modules. i used below code for the other module :

;ModuleID = ‘MyOwnFunction’
define i32 @MyOwnFunction() {
entry:
ret i32 55
}

should i use any especial switch to compile or what should i chane in my codes? I received error by below command also :

$ lli -load MyOwnFunction.bc m1.bc

Try something like the following?

llvm-link MyOwnFunction.bc m1.bc -o - | lli

-Eli

Eli Friedman <eli.friedman <at> gmail.com> writes:

Try something like the following?

llvm-link MyOwnFunction.bc m1.bc -o - | lli

-Eli

same error again!

Strange... it works for me. Maybe try reading the docs for llvm-link?

$ llvm-as -o m1.bc

define i32 @main() {
entry:
%tmp0 = call i32 @MyOwnFunction()
ret i32 0
}
declare i32 @MyOwnFunction()

$ llvm-as -o MyOwnFunction.bc

;ModuleID = 'MyOwnFunction'
define i32 @MyOwnFunction() {
entry:
ret i32 55
}

$ llvm-link m1.bc MyOwnFunction.bc -o - | lli
$

-Eli