GCC Cross-Compiler: Difference between revisions

m
Reverted edits by Max (talk) to last revision by Requimrar
[unchecked revision][unchecked revision]
m (Make some small improvements, also to fix notice on top)
m (Reverted edits by Max (talk) to last revision by Requimrar)
Line 1:
{{FirstPerson}}
{{rating|1}}
ThisIn this tutorial focuseswe oncwill reatingcreate a GCC cross-compiler for your own operating system. This compiler thatis wespecially buildmade hereto willtarget haveexactly ayour genericoperating targetsystem (i686-elf)and is what allows you to leave the current operating system behind, meaning that no headers or libraries of your host operating system will be used. You ''need'' a cross-compiler for operating systemsystems development, otherwiseunless ayou lotare of unexpected things can happen because the compiler assumes that your code is runningdeveloping on your hostown operating system.
 
== Introduction ==
 
Generally speaking, a cross-compiler is a compiler that runs on platform A (the '''host'''), but generates executables for platform B (the '''target'''). These two platforms may (but do not need to) differ in CPU, operating system, and/or [[:Category:Executable Formats|executable format]]. In our case, the host platform is your current operating system, and the target platform is the operating system you are about to make. It is important to realize that these two platforms are not the same; your operating system is always going to be different from your current operating system. This is why we need to build a cross-compiler first, you will most certainly run into trouble otherwise.
 
=== Why cross-compilersdo areI necessaryneed a Cross Compiler? ===
{{Main|Why do I need a Cross Compiler?}}
 
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. If you have already attempted to make an operating system without using a cross-compiler, please read the article [[Why do I need a Cross Compiler?]].
 
=== Which compiler version todo chooseI want? ===
{{Main|Building GCC}}
 
Line 25:
You may be able to use an older major GCC release to build a cross-compiler of a newer major GCC release. For instance, GCC 4.7.3 may be able to build a GCC 4.8.0 cross-compiler. However, if you want to use the latest and greatest GCC version for your cross-compiler, we recommend that you [[Building GCC|bootstrap the newest GCC]] as your system compiler first. Individuals using OS X 10.7 or earlier might want to invest in either building a system GCC (that outputs native Mach-O), or upgrading the local LLVM/Clang installation. Users with 10.8 and above should install the Command Line Tools from Apple's developer website and use Clang to cross-compile GCC.
 
=== Which binutilsBinutils version todo chooseI want? ===
{{Main|Cross-Compiler Successful Builds}}
We recommend that you use the latest and greatest [[Binutils]] release. Note, however, that not all combinations of GCC and Binutils work. If you run into trouble, use a Binutils that was released at roughly the same time as your desired compiler version. You probably need at least Binutils 2.22, or preferably the latest 2.23.2 release. It doesn't matter what Binutils version you have installed on your current operating system.
Line 168:
 
This will allow the build to proceed. The reason this happens is that the <tt>mingw32</tt> (and mingw itself) configures <tt>INCLUDE_PATH</tt> and <tt>LIBRARY_PATH</tt> to be, as can be guessed, <tt>/mingw/include</tt> and <tt>/mingw/lib</tt>, instead of the defaults <tt>/usr/include</tt> and <tt>/usr/lib</tt>. Why the build fails even though nothing is required in those folders, and why it doesn't just make them, is beyond me.
 
== More advanced ==
Using this simple cross compiler will be sufficient for quite some time, but at some point you will want the compiler to automatically include your own system headers and libraries. Building an [[OS Specific Toolchain|OS-specific toolchain]] for your own operating system is the way to go from here.
 
== See Also ==
Anonymous user