2016-12-04 9 views
0

私はOS X 10.12を実行しており、基本的なテキストベースのオペレーティングシステムを開発しています。私はブートローダを開発しており、うまく動作しているようです。私の唯一の問題は、カーネルを純粋なバイナリにコンパイルしようとすると、リンカが動作しなくなることです。私はいくつかの調査をしましたが、これはOS XがGNUリンカーではなくDarwinリンカーを実行していることが原因であると考えています。このため、私はGNU binutilsをダウンロードしてインストールしました。しかし、それはまだ動作しません...ここでDarwinリンカの代わりにGNUリンカを使用するにはどうすればよいですか?

は私のカーネルです:

void main() { 
    // Create pointer to a character and point it to the first cell of video 
    // memory (i.e. the top-left) 
    char* video_memory = (char*) 0xb8000; 

    // At that address, put an x 
    *video_memory = 'x'; 
} 

そして、私はそれをコンパイルしようとすると、これは次のとおりです。

Hazims-MacBook-Pro:32 bit root# gcc -ffreestanding -c kernel.c -o kernel.o 
Hazims-MacBook-Pro:32 bit root# ld -o kernel.bin -T text 0x1000 kernel.o --oformat binary 
ld: unknown option: -T 
Hazims-MacBook-Pro:32 bit root# 

私は方法を知っているのが大好きですこの問題を解決する。あなたの時間をありがとう。

+0

余分なスペースがあり、 '-T text 0x1000'の' = '記号が欠けています。これは' -Ttext = 0x1000'でなければなりません。マニュアルを参照してください。それでも動作しない場合は、マニュアルに従って再度 '--section-start = .text = 0x1000'を試してください。 – Jester

+0

@Jesterあなたが言ったことを試してみると、このエラーが表示されます: 'ld:unknownオプション:--section-start = .text = 0x1000' –

+0

'ld --version'とは何ですか? – Jester

答えて

0

-Tはgccコンパイラフラグであり、リンカフラグではありません。

With these components you can now actually build the final kernel. We use the compiler as the linker as it allows it greater control over the link process. Note that if your kernel is written in C++, you should use the C++ compiler instead.

You can then link your kernel using:

i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc

Note: Some tutorials suggest linking with i686-elf-ld rather than the compiler, however this prevents the compiler from performing various tasks during linking.

The file myos.bin is now your kernel (all other files are no longer needed). Note that we are linking against libgcc, which implements various runtime routines that your cross-compiler depends on. Leaving it out will give you problems in the future. If you did not build and install libgcc as part of your cross-compiler, you should go back now and build a cross-compiler with libgcc. The compiler depends on this library and will use it regardless of whether you provide it or not.

これは、すべてのOSDevから直接取得され、非常に明確に、最低限のカーネルを含め、全体のプロセスを文書化:これを見ています。

+0

これは当てはまりますが、私はOPが '-Ttext'オプションを持つセクションの開始を設定しようとしていると思います。 – Jester

+0

私のリンカーでなければなりません。 '-T'オプションはありません。 :) –

+0

@DavidHoelzerこれは私にこのエラーを与える 'Hazims-MacBook-Pro:32ビットルート#gcc -T 0x1000 -o myos.bin -ffreestanding kernel.c //// ld:未知のオプション:-T /// // clang:エラー:リンカーコマンドが終了コード1で失敗しました(呼び出しを見るには-vを使用してください) ' –

関連する問題