我正在尝试在汇编器上编译并链接我的第一个程序。
我尝试编译以下代码:
; %include "stud_io.inc"
global _main
section .text
_main:
xor eax, eax
again:
; PRINT "Hello"
; PUTCHAR 10
inc eax
cmp eax, 5
jl again
下面是用于编译和链接程序的控制台命令:
-bash-3.2$ nasm -f macho main.asm -o main.o && ld -e _main -macosx_version_min 10.8 -arch x86_64 main.o
但结果是:
ld: warning: ignoring file main.o, file was built for i386 which is not the architecture being linked (x86_64): main.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
-u command line option
ld: symbol(s) not found for architecture x86_64
我认为有必要为x86_64编译main.asm文件..
如何正确地为我的系统编译程序?
我建议首先更新您的NASM http://www.nasm.us/pub/nasm/releasebuilds/2.10/.
之后,尝试运行以下命令:
nasm -f macho64 main.asm -o main.o && ld -e _main -macosx_version_min 10.8 -arch x86_64 main.o -lSystem
请注意,新命令添加了上面 JasonD 的建议(macho64
),还添加了-lSystem
to the ld
命令阻止 ld 抛出以下错误:
ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)