Dan*_*och 4 macos assembly gcc nasm osx-snow-leopard
我正在尝试使用NASM学习装配,来自Paul Carter博士的pcasm-book.pdf - http://www.drpaulcarter.com/pcasm/ - 在我的Mac OS X Snow Leopard上.
我正在尝试将以前编译的C示例链接到asm示例:
gcc first.o driver.c asm_io.o -o first
Run Code Online (Sandbox Code Playgroud)
但它正在归还它:
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
Run Code Online (Sandbox Code Playgroud)
我正在使用Mach-o格式来编译asm样本,我没有错误:
nasm -f macho **first.asm**
nasm -f macho asm_io.asm
Run Code Online (Sandbox Code Playgroud)
如果我尝试在driver.c中仅使用gcc -c,使用ld链接所有目标文件,ld似乎不链接driver.o格式.
ld -o first asm_io.o first.o driver.o
Run Code Online (Sandbox Code Playgroud)
它返回:
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
Run Code Online (Sandbox Code Playgroud)
有什么问题?在OS X上使用gcc和NASM的正确格式是什么?
谢谢.丹尼尔科赫
"文件不是必需的体系结构"表示您正在尝试链接具有不同体系结构的对象文件:可能是x86_64和i386.因为看起来您的nasm输出是i386,请尝试使用-arch i386gcc.您还可以使用它file来显示给定对象文件或库的体系结构.
% touch foo.c ; gcc -c foo.c
% file foo.o
foo.o: Mach-O 64-bit object x86_64
% gcc -c -arch i386 foo.c
% file foo.o
foo.o: Mach-O object i386
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2728 次 |
| 最近记录: |