デフォルトでXcodeにインストールされているnasmとldを使用して、64ビットMac OS X Lionを使用して基本的なアセンブリファイルを実行しようとしています。
文字を出力するアセンブリ ファイルを作成し、nasm を使用してビルドしました。
nasm -f elf -o program.o main.asm
ただし、ld とリンクしようとすると、かなりの数のエラー/警告で失敗します。
ld -o program program.o
ld: warning: -arch not specified
ld: warning: -macosx_version_min not specificed, assuming 10.7
ld: warning: ignoring file program.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
ld: warning: symbol dyld_stub_binder not found, normally in libSystem.dylib
ld: entry point (start) undefined. Usually in crt1.o for inferred architecture x86_64
そのため、これらの問題のいくつかを修正しようとしましたが、どこにも行きませんでした.
これが私が試したことの1つです:
ld -arch i386 -e _start -o program program.o
これはうまくいくと思っていましたが、間違っていました。
オブジェクト ファイルを、nasm と ld が一致する互換性のあるアーキテクチャにするにはどうすればよいでしょうか?
また、プログラムのエントリ ポイントをどのように定義しますか (現在、私は上記のglobal _start
in を使用していますが、あまり効果がないようです)。.section text
_start
ld を使用してオブジェクト ファイルをバイナリ ファイルに正常にリンクする方法について少し混乱しています。それらを一致させるコード (または nasm または ld への引数) が不足していると思います。
どんな助けでも感謝します。