2014-10-30 84 views
1

我正在使用優勝美地的Macbook Pro。無法讓printf工作。這裏是我的代碼:分段錯誤調用printf NASM

extern _printf 
global _main 

section .data 

msg: db  "Hello World" 

section .text 

_main: 
    push  msg 
    call  _printf 
    add   esp, 4 
    ret 

使用:

nasm -f macho test.s && gcc -arch i386 -e _main test.o && ./a.out 

輸出:

ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _main from test.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie 
Segmentation fault: 11 

我真的很感激任何幫助。

回答