Hi,
I'm trying to compile small assembly routine (nasm) which print a message to the console using the puts c-function.
Unfortunately every time I try to compile it, I get "undefined symbol". If I replace "puts" with "_puts" then program compile without any errors or warnings but when I try run it "segementation fault" occurs.
I'm trying to compile small assembly routine (nasm) which print a message to the console using the puts c-function.
Unfortunately every time I try to compile it, I get "undefined symbol". If I replace "puts" with "_puts" then program compile without any errors or warnings but when I try run it "segementation fault" occurs.
Code:
nasm -f macho eatclib.asm
gcc -arch i386 -o eat eatclib.o
Undefined symbols:
"puts", referenced from:
_main in eatclib.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Code:
[SECTION .data]
EatMsg: db "Eat at Joe's!",0
[SECTION .bss]
[SECTION .text]
extern puts
global _main
_main:
push ebp
mov ebp,esp
push ebx
push esi
push edi
push EatMsg
call puts
add esp,4
pop edi
pop esi
pop ebx
mov esp,ebp
pop ebp
ret
Code:
gcc -v
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc/gcc-5646.1~2/src/configure --disable-checking --enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-gxx-include-dir=/include/c++/4.2.1 --program-prefix=i686-apple-darwin10- --host=x86_64-apple-darwin10 --target=i686-apple-darwin10
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5646) (dot 1)