4
我正在嘗試使用NASM學習程序集,Paul Carter博士的pcasm-book.pdf - http://www.drpaulcarter.com/pcasm/ - 在我的Mac OS X Snow Leopard上。OSX中gcc使用的文件格式是什麼?
我想以前編譯的C樣品鏈接到ASM樣本:
gcc first.o driver.c asm_io.o -o first
但它返回它:
driver.c:3: warning: ‘cdecl’ attribute ignored
ld: warning: in first.o, **file is not of required architecture**
ld: warning: in asm_io.o, file is not of required architecture
Undefined symbols:
"_asm_main", referenced from:
_main in ccjLqYJn.o
ld: symbol(s) not found
我使用的Mach-O的格式編寫彙編樣本,我沒有錯誤:
nasm -f macho **first.asm**
nasm -f macho asm_io.asm
如果我嘗試在driver.c中只使用gcc -c,使用ld鏈接所有目標文件,l d似乎沒有鏈接driver.o格式。
ld -o first asm_io.o first.o driver.o
它返回:
ld: warning: in driver.o, file is not of required architecture
Undefined symbols:
"_putchar", referenced from:
print_char in asm_io.o
print_nl in asm_io.o
"_printf", referenced from:
print_int in asm_io.o
print_string in asm_io.o
push_of in asm_io.o
sub_dump_stack in asm_io.o
stack_line_loop in asm_io.o
sub_dump_mem in asm_io.o
mem_outer_loop in asm_io.o
mem_hex_loop in asm_io.o
sub_dump_math in asm_io.o
tag_loop in asm_io.o
print_real in asm_io.o
invalid_st in asm_io.o
"_scanf", referenced from:
read_int in asm_io.o
"_getchar", referenced from:
read_char in asm_io.o
ld: symbol(s) not found for inferred architecture i386
什麼問題?在OS X上使用gcc和NASM的正確格式是什麼?
謝謝。 Daniel Koch
謝謝。 Gcc默認使用x86_64,而NASM的「macho」格式是i386。 – 2009-12-16 03:37:36
@DanielKoch你可以發佈什麼最終爲你工作?我仍然收到編譯錯誤。 – gideon 2013-10-27 10:05:29
@gideon你可能應該發佈一個新問題或者包含一個鏈接到你正在嘗試的命令和你正在看到的錯誤。或者描述你對我的反應不瞭解,所以我可以改進它。 – 2013-10-27 15:57:50