I am practicing C and assembly language mix programming using GCC. And this error occered:
1 deng@ubuntu:~/workspace/leos_test$ make
2 ld -o deng c.o asm.o
3 ld: warning: cannot find entry symbol _start; defaulting to 0000000008048074
4 c.o: In function `main':
5 c_and_asm.c:(.text+0x19): undefined reference to `add'
6 c_and_asm.c:(.text+0x2e): undefined reference to `printf'
7 make: *** [deng] Error 1
This is the C code:
1 #include<stdio.h>
2 void extern add(int * i);
3 void main(){
4 int i=1;
5 add(&i);
6 printf("%d ",i);
7}
Here is the assembly language code:
1 .globl _add
2 _add:
3 push %bp;
4 mov %sp,%bp;
5 mov 0x4(%bp),%eax;
6 incw (%eax);
7 popw %bp;
8 ret
This is the makefile:
1 deng: c.o asm.o
2 ld -o deng c.o asm.o
3 c.o:
4 gcc -o c.o -c c_and_asm.c
5 asm.o:
6 as -o asm.o c_asm.asm
Any suggestion will be appreciated 🙂 .
Change your c_asm.asm file to this:
include in your ld this parameter
-lcand better change the file extension to.s