Building C/C++ cross toolchain

Assembler, C/C++ related topics

Building C/C++ cross toolchain

Postby simon » Fri Sep 21, 2012 2:52 pm

Hello,

to program C/C++, a (cross) compiler is needed. I use a GCC based cross toolchain running on Linux.

First we have to get the needed packages. Create a directory (e.g. /home/foo/Cross_m68k/) where you build the toolchain.

Dowload these three packages and extract each into above directory:
  • Binutils - with this, you get the GNU assembler, linker, objdump, etc
  • GCC - the GNU compiler itself
  • Newlib - an alternative C library

Code: Select all
ray Cross_m68k # tar zxvf binutils-2.22.tar.gz
ray Cross_m68k # cd binutils-2.22
ray binutils-2.22 # mkdir m68k-obj
ray binutils-2.22 # cd ..

ray Cross_m68k # tar zxvf gcc-4.7.0.tar.gz
ray Cross_m68k # cd gcc-4.7.0
ray gcc-4.7.0 # mkdir m68k-obj
ray gcc-4.7.0 # cd ..

ray Cross_m68k # tar zxvf newlib-1.20.0.tar.gz
ray Cross_m68k # cd newlib-1.20.0
ray newlib-1.20.0 # mkdir m68k-obj
ray newlib-1.20.0 # cd ..


Now, we are going to build and install the toolchain. We install it into /usr/local/m68k/ to seperate it from the usual toolchain. You can either set a PATH environment variable or create symbolic links to your /usr/bin/.

Before we can build the compiler itself, we need to build the binutils as the compiler depends on it:
Code: Select all
ray Cross_m68k # cd binutils-2.22/m68k-obj/
ray m68k-obj # ../configure --target=m68k-elf --prefix=/usr/local/m68k/
ray m68k-obj # make
ray m68k-obj # make install
ray m68k-obj # cd ../../


The full compiler depends on parts of Newlib, so we first build a "half" working GCC compiler (bootstrap):
Code: Select all
ray Cross_m68k # cd gcc-4.7.0/m68k-obj/
ray m68k-obj # ../configure --target=m68k-elf --prefix=/usr/local/m68k/ --enable-languages=c,c++ --with-newlib --disable-libmudflap --disable-libssp --disable-libgomp --disable-libstdcxx-pch --disable-threads --with-gnu-as --with-gnu-ld --disable-nls --with-headers=yes --disable-checking --without-headers --disable-shared
ray m68k-obj # make
ray m68k-obj # make install
ray m68k-obj # cd ../../


Now we have a cross compiler, which is already able to build the Newlib:
Code: Select all
ray Cross_m68k # cd newlib-1.20.0/m68k-obj/
../configure --target=m68k-elf --prefix=/usr/local/m68k/ --enable-languages=c,c++ --with-newlib --disable-libmudflap --disable-libssp --disable-libgomp --disable-libstdcxx-pch --disable-threads --with-gnu-as --with-gnu-ld --disable-nls --with-headers=yes --disable-checking --with-headers --disable-shared
ray m68k-obj # make
ray m68k-obj # make install
ray m68k-obj # cd ../../


After building and installing Newlib, we go back to the GCC directory to build and install the full cross compiler with support of Newlib:
Code: Select all
ray Cross_m68k # cd gcc-4.7.0
ray gcc-4.7.0 # ln -sf ../newlib-1.20.0/newlib/ newlib
ray gcc-4.7.0 # cd m68k-obj/
../configure --target=m68k-elf --prefix=/usr/local/m68k/ --enable-languages=c,c++ --with-newlib --disable-libmudflap --disable-libssp --disable-libgomp --disable-libstdcxx-pch --disable-threads --with-gnu-as --with-gnu-ld --disable-nls --with-headers=yes --disable-checking --with-headers --disable-shared
ray m68k-obj # make
ray m68k-obj # make install


Now you should have a working C/C++ cross compiler toolchain:
Code: Select all
ray m68k-obj # m68k-elf-gcc --version
m68k-elf-gcc (GCC) 4.7.0
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Simon
simon
Site Admin
 
Posts: 686
Joined: Thu Sep 13, 2012 9:35 am
Location: Luedenscheid, Germany

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron