< User:Max

In this tutorial you will learn how to build a GCC cross compiler toolchain on Mac OS X (10.9, Mavericks). This includes building cross binutils, a cross compiler and libgcc for your target architecture.

To do this tutorial, I assume that you have a basic knowledge about using the Terminal and commands like cd and mkdir.

Jul 13, 2018. The GNU Compiler Collection (GCC) is a compiler system produced by the GNU Project supporting various programming languages.GCC is a key component of the GNU toolchain and the standard compiler for most projects related to GNU and Linux, including the Linux kernel.The Free Software Foundation (FSF) distributes GCC under the GNU General Public License (GNU GPL).

OSX-replace gcc version 4.2.1 with 4.9 installed via Homebrew (3). By default, homebrew places the executables (binaries) for the packages it installs into /usr/local/bin - which is a pretty sensible place for binaries installed by local users when you think about it - compared to /bin which houses standardisded binaries belonging to the core OS.

Download gcc-4.9-base packages for Ubuntu. Ubuntu Universe amd64 Official gcc-4.9-base4.9.3-13ubuntu2amd64.deb: GCC, the GNU Compiler Collection (base package). Dec 11, 2017.

  • 4Building
    • 4.4Checking the installation

Installing GCC

To build a cross compiler from the GCC sources, you first need to have the GNU GCC installed on your system (called the 'host system'). This compiler will later be used to compile the cross-toolchain.

There might already be a compiler showing up when using gcc in Terminal, but this is not the actual GNU GCC, it's Apples LLVM compiler. To install the real GNU GCC, we use Homebrew. Once you have Homebrew installed, open up a Terminal. Then install GCC with the brew commands: Drum pad machine apk free download.

This may take a while. It installs the GNU GCC 4.9 with additional support for C++. You should then check if GCC is working by using 'gcc-4.9 --version' in the Terminal.

Installing the necessary libraries

For building GCC you also need to install the libraries GMP, MPFR and MPC on your host system. You can do this with the following brew commands:

Once this is done, the necessary libraries are available on your system, and you are ready for building the cross compiler.

Downloading the sources

The following sources are required to build the cross compiler toolchain. The versions here are the ones I'll be using in the following (and that are in the moment I'm writing this the newest sources). Any newer/older version might - or might not - work as well.

Once you've downloaded the archive files of the current sources (namely in our case gcc-4.9.0.tar.gz and binutils-2.24.tar.gz), create a folder in your home directory (name it for example src) and unpack the archives there.

Building

Open up a terminal and cd to the src directory we just created. Inside of that directory, you should now have the folders gcc-4.9.0 and binutils-2.24 containing our necessary sources.

Preparing environment variables

We will now set some environment variables for the build process by using the export command. Take care - these variables are temporary, if you open a new terminal session, you'll have to enter them again.

First, we set the compiler variables right, to let the configure script and makefiles of binutils and gcc know that they need to use the compiler we just installed instead of the LLVM:

Also, we define the following variables. The PREFIX is the path where you want to install the cross-binaries to. The TARGET determines your target platform, for example we want to build an i686-elf compiler. The PATH export we're doing here just appends the directory that you specified as the target for your cross-binaries to the PATH.

Now we are ready to continue building binutils and then the gcc and libgcc.

Gcc

binutils

  1. Create a folder binutils-2.24-build in your ~/src folder
  2. cd to that folder
  3. From inside of that folder, we now run the configure script of binutils:
  4. Once the configure script has successfully completed its work, perform the build and installation:

gcc and libgcc

  1. Create a folder gcc-4.9.0-build in your ~/src folder
  2. cd to that folder
  3. From inside of that folder, we now run the configure script for GCC:
    (Note: the configure script might throw an error about not finding the installation of MPC/GMP/MPFR. To make it find these libraries, use the respective '--with-*' parameter. When using brew, this is by default '/usr/local', so '--with-gmp=/usr/local' etc. should work)
  4. Once the configure script has successfully completed its work, perform the build and installation:

Checking the installation

You can now check if the cross compiler works by typing i686-elf-g++ --version. To make the new cross tools always available in Terminal, you will have to open your user .bash_profile like this:

Now, add the following line (if you changed where you installed your crosstools to, you have to change it accordingly):

Press ^x for saving, press y and then enter to confirm saving. The crosstools are now in your PATH and are available in your Terminal.

Location of crosstools and target-libgcc

Gcc 4.9.4 Download

If you used the PREFIX variable from above, you should find a opt folder in your home directory. Inside of that folder is a cross folder, which contains all the stuff we just built. This folder contains:

  • a bin folder with the binaries of the cross compiler
  • a lib/gcc/i686-elf/4.9.0/ folder which contains a include folder and libgcc.a for linking it with your kernel

Gcc 4.9 Download Mac High Sierra

Retrieved from 'https://wiki.osdev.org/index.php?title=User:Max/Building_a_GCC_4.9_cross_compiler_on_OS_X_Mavericks&oldid=18219'