How the **** did this reached there. The Ghost Kernel is one of
max's projects. You should
not use it! Don't misunderstand me; max is an excellent developer, but precompiled binaries are the hell on Earth.
This will be a somewhat lengthy post. I'll try to explain you what does the wiki perfectly explains. If this doesn't solutions the problem, I don't know what will.. I'll try to explain you the basics of cross-compilation, using the wiki
. Before proceding, remember to read all the post before doing anything, specially the caveats at the end.
First of, why do you/I need a cross-compiler?
The Holy OSDev Wiki wrote:
You need to use a cross-compiler unless you are developing on your own operating system. The compiler must know the correct target platform (CPU, operating system), otherwise you will run into trouble. If you use the compiler that comes with your system, then the compiler won't know it is compiling something else entirely. Some tutorials suggest using your system compiler and passing a lot of problematic options to the compiler. This will certainly give you a lot of problems in the future and the solution is build a cross-compiler.
First of all, get the
lastest GCC sources. Extract them somewhere
. Do the same with the
lastest binutils sources.
Do not mix both extracted folders!
The wiki says that you'll now need to "decide" your [link=http://wiki.osdev.org/Target_Triplet]Target Triplet[/link]. Let's just use
i686-elf for this guide. Now, let's prepare for the build! This either can or cannot is a damn hard part for Cygwin/MinGW users. You'll have to get through your GNU on Windows environment. You'll need the following packages:
- GCC
- G++
- GNU Make
- GNU Bison
- GNU Flex
- GNU Diffutils
The wiki says you must also download GMP/MPFR/MPC. Do not! They're GCC's math/who knows what else supporting libraries. In my experience, GCC Make process tends to blindly miss these packages' folders once extracted on GCC's source folder. This is not any good, as compilation will simply fail with a frustrating
make: ** error 1 **-like message. But we still need the libraries! There is a pretty clever and uniform solution to this problem. Assuming you extracted GCC to a directory named
gcc-src, run these commands:
Code: Select all
cd gcc-src
./contrib/download_prerequisites
Just go, take a drink, and GCC will automatically download, unpack, and correctly place the necessary dependencies for you. Note that you need
wget for this to even work.
We're ready! Let's start by creating some pretty folders (
this is mandatory!). If you're still in
gcc-src, run this:
Code: Select all
cd ..
mkdir gcc-bld
mkdir binutils-bld
The following commands must be ran exactly as shown or compilation will fail, and you'll have to start over from zero!
Just to be sure, take this religiously
. If, by some reason, your terminal session is closed (power outage, etc..), you must refollow the following paragraph again.
We need to do some exports. This will allow the build system to understand where you want to build the cross-compiler.
Never mind to avoid this step! We'll export three variables, first of all,
$PREFIX. It is where your cross-compiler will be installed. Reserve a folder somewhere in your system for this. Let's say it's
$HOME/cross (change this to your needs). Let's export it!:
Now, another variable,
$TARGET. It defines what platform your cross-compiler will compile for. I have said you that in this guide we'ld use
i686-elf, that is, it will target Pentium Pro or newer processors.
The third variable will be exported later, but it's still important. It's actually
$PATH. We'll redefine it so that we can call
i686-elf-* from outside
$PREFIX.
We are fully prepared, it's compile time! Run this
exactly exactly as shown! We'll compile binutils first. Assuming you're still where I left you, do this. (Note: this assumes binutils sources are in a directory called
binutils-src. In real world, it probably won't. Just modify the script to use the correct paths
):
Code: Select all
cd binutils-bld
../binutils-src/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
make install
This should run perfectly. If a minimal error occurs, the build will fail. In such a case, just post us the lastest lines before to the abort. Just for completeness, I'll explain each of the options. The first two are pretty trivial.
--with-sysroot will force the build system to create a new
/usr-like environment inside
$PREFIX. This will help GCC later on.
--disable-nls will disable Native Language Support. That is, if you're German for example, you'll get messages in English, not German. This is optional, but makes compilation faster and prints messages we (the forum people
) can understand.
It's time for GCC, finally! Run:
Code: Select all
cd ../gcc-bld
../gcc-src/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc all-target-libgcc
make install-gcc install-target-libgcc
This will take a long time, usually 2 or 3 times more than binutils
. GCC's build is much more propense to disasters, so be aware for any errors! Again, I'll explain the flags. The first three are the same than for binutils.
--enable-languages is pretty trivial; it creates compilers for C and C++.
--without-headers alerts GCC that there won't be any runtime C(++) standard support library for the target. These commands also build
libgcc, a library that GCC
can generate calls to without any way to avoid it!. All GCC-compiled programs will be linked with
libgcc. It implements some software-computed features that the target hardware is unable to handle, such as 64-bit division in
i686-elf.
Once done, you'll have your fresh, just baked cross-compiler ready for the go. We'll just modify
$PATH so that it can be accessed from anywhere:
Run the above snippet every time you open MinGW (or is there a
.bashrc in MinGW
?)
I'll just post a few more caveats and exit:
- Use tar to extract the archives. Don't use a Windows-specific tool. It may change Unix-newlines ("\n") to stupid Windows-newlines ("\n\r"). This is not any good, as compilation can get pretty messy really fast.
- Don't stop the compilation (either voluntarily or not), neither close your MinGW terminal! It may be very difficult to recover from this, as you'll have to start from zero!.
- Follow what the people on this forum say you. Don't persist on using "easy" prebuilt-compilers. They'll cause you lots of problems.
- If you have the oportunity, install (either as dual-boot or single OS) a Linux distribution. If you really like OSDev, this will help you a lot!