[NASM / Linux] Problème de linkage avec lib C
Bonjour,
J'ai compile le code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
;importing exter C symbol
extern _printf
;declarating variables
section .data
;filling the variable
hello: db 'Hello World', 10, 0
;entry point for main function
global _main
;start assembly program
section .text
;coding the _main symbol
_main:
;pushing the hello variable on the stack
push hello
;calling the _printf C function
call _printf
;cleaning the stack by unstacking the hello variable on the EAX register
pop EAX
;exiting from _main symbol
ret |
Afin de pratiquer l'inclusion de symbols C dans le code assembleur.
Pour compiler (je travaille sous Linux) j'ai fait :
Code:
1 2
|
nasm -f elf -o hello.o hello.asm |
Et tout parait bien marcher...
J'ai regarde sur internet pour pouvoir linker ca a la lib de C et j'ai fait :
Code:
1 2
|
ld -o hello -lc hello.o |
La reponse que j'obtient est :
Code:
1 2 3 4
|
ld: warning: cannot find entry symbol _start; defaulting to 0000000008048100
hello.o: In function `_main':
hello.asm:(.text+0x6): undefined reference to `_printf' |
Comment resoudre ca ?
Merci d'avance.