如何编译使用MacOSX上NASM

如何编译使用MacOSX上NASM

本文介绍了如何编译使用MacOSX上NASM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译和链接汇编我的第一个程序。
我尝试编译以下code:

I am trying to compile and link my first program on Assembler.I try to compile the following code:

; %include "stud_io.inc"
global _main

section .text
_main:
    xor eax, eax
again:
    ; PRINT "Hello"
    ; PUTCHAR 10
    inc eax
    cmp eax, 5
    jl again

下面的编译和链接程序的控制台命令:

Below the console command for compiling and linking a program:

-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中..
如何编译我的系统程序是否正确?

I think its necessary to compile the main.asm file for x86_64..How to compile programs for my system properly?

推荐答案

我会建议先更新您的。

在此之后,尝试运行这样的:

After that, try running this:

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 来的 LD 命令从抛出以下错误停止LD:

Notice that the new command adds JasonD's suggestion above (macho64), but also adds the -lSystem to the ld command to stop ld from throwing following error:

ld: dynamic main executables must link with libSystem.dylib for architecture x86_64

这篇关于如何编译使用MacOSX上NASM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 11:51