我正在尝试在Mac上的终端中运行以下代码:
.section, .data
format_string:
.asciz "My favorite number is %d!"
number:
.long 786
.section, .text
.globl main
main:
pushl number
pushl $format_string
call printf
addl $8, %esp
pushl $0
call exit
此代码位于名为favorite.s
的文件中我使用了命令“gcc favorite.s -m32”并看到以下消息:
Undefined symbols for architecture i386:
"_main", referenced from:
start in crt1.10.6.o
"exit", referenced from:
main in ccUKdD8O.o
"printf", referenced from:
main in ccUKdD8O.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
我在这里做错了什么?感谢。
答案 0 :(得分:5)
在Mac OS X上,符号前缀为下划线。在程序中_
,main
和exit
前面添加printf
,然后重试!