5

macos用のnasmプログラムのリンクに問題があります。

GLOBAL _start
SEGMENT .text
_start:
    mov ax, 5
    mov bx, ax
    mov [a], ebx
SEGMENT .data
a   DW 0
t2  DW 0

fry$ nasm -f elf  test.asm
fry$ ld -o test test.o -arch i386
ld: warning: in test.o, file was built for unsupported file format which is not the architecture being linked (i386)
ld: could not find entry point "start" (perhaps missing crt1.

fry$ nasm -f macho  test.asm
fry$ ld -o test test.o -arch i386
ld: could not find entry point "start" (perhaps missing crt1.o)

誰かが私を助けることができますか?

4

3 に答える 3

7

MacOSXリンカーはELFオブジェクトをリンクできません。Mach-O実行可能フォーマットでのみ動作します。オブジェクトファイルを変換する方法を理解したい場合を除いて、MacOSXアセンブラで動作するコードを作成する方がよいでしょう。

編集:@Fryが以下のコメントで言及しているように、nasmMach-Oオブジェクトを出力することができます。その場合、問題は単純です。ソースファイルの両方の場所で_離陸します。_start結果はうまくリンクします。

于 2010-05-25T22:13:13.120 に答える
6
nasm -f macho test.asm

ld -e _start -o test test.o
于 2010-12-07T00:46:04.947 に答える
1

elf形式に固執してMacで開発する必要がある人には、クロスコンパイラが必要です...

http://crossgcc.rts-software.org/doku.php?id=compiling_for_linux

次に、これに似たものに進むことができます...

/usr/local/gcc-4.8.1-for-linux32/bin/i586-pc-linux-ld -m elf_i386 -T link.ld -o kernel kasm.o kc.o
于 2015-12-03T16:46:36.617 に答える