I have this simple C source code :
#include <stdio.h>
extern int Sum(int,int);
int main()
{
int a,b,s;
a=1 , b=2;
s = Sum(a,b);
return 0;
}
and i have this s.asm which defines the function _Sum :
global _Sum
_Sum:
push ebp ; create stack frame
mov ebp, esp
mov eax, [ebp+8] ; grab the first argument
mov ecx, [ebp+12] ; grab the second argument
add eax, ecx ; sum the arguments
pop ebp ; restore the base pointer
ret
now , i compiled the .asm using :
nasm s.asm -f elf -o s.o
and compiled and linked the .c file using :
gcc s.o test.o -o testapp
this is the outcome :
/tmp/ccpwYHDQ.o: In function `main':
test.c:(.text+0x29): undefined reference to `Sum'
collect2: ld returned 1 exit status
So what is the problem ?
I'm using Ubuntu-Linux
Any help would be greatly appreciated , Thanks
[SOLVED] : i checked with nm the test.o file and it expected to find the symbol 'Sum' not '_Sum' so changing that solved the problem.
extern int Sum(int,int);
global _Sum
somewhere in the asm sideglobal _Sum
instead of just_Sum
, i got the same error message @haroldextern int Sum(int,int);
instead of the old one , and i got the same error message @RageD