Macos 什么';OSX中gcc使用的文件格式是什么?
我正试图在我的Mac OS X Snow Leopard上使用NASM(保罗·卡特博士提供的pcasm-book.pdf)学习汇编 我正在尝试将以前编译的C示例链接到asm示例:Macos 什么';OSX中gcc使用的文件格式是什么?,macos,gcc,assembly,osx-snow-leopard,nasm,Macos,Gcc,Assembly,Osx Snow Leopard,Nasm,我正试图在我的Mac OS X Snow Leopard上使用NASM(保罗·卡特博士提供的pcasm-book.pdf)学习汇编 我正在尝试将以前编译的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*
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格式编译asm示例,没有出现错误:
nasm -f macho **first.asm**
nasm -f macho asm_io.asm
如果我尝试在driver.c中仅使用gcc-c,使用ld链接所有对象文件,ld似乎不会链接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
有什么问题吗?在OSX上使用gcc和NASM的正确格式是什么
多谢各位。
Daniel Koch该“文件不是必需的体系结构”表示您正在尝试将对象文件与不同的体系结构链接:可能是x86_64和i386。由于您的nasm输出是i386,请尝试将-arch i386
与gcc一起使用。您还可以使用文件
显示给定对象文件或库的体系结构
% 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
非常感谢。Gcc默认使用x86_64,而NASM的“macho”格式是i386。@DanielKoch,你能发布什么最终对你有用吗?我仍然有编译错误。@gideon您可能应该发布一个新问题,或者包含一个链接,指向您正在尝试的命令和看到的错误。或者描述一下你对我的回答不理解的地方,这样我可以改进它。很好的提醒@NicholasRiley。我整天都在做这件事(实际上是试图构建一个交叉编译器集合,并编译paul carters博士的书中的程序。不幸的是,出现了第二个问题,因为他使用c运行时库,需要有一个x86版本的库。因此,以下评论中的所有步骤对我都有效:(1)
nasm-f elf32 first.asm
(2)gcc-m32-lc-o first.o driver.c asm_io.o
这是在安装之后:sudo yum install glibc-devel.i686 libstdc++-devel.i686