This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Building a cross-compiler for a Raspberry Pi
- From: YuGiOhJCJ Mailing-List <yugiohjcj-mailinglist at laposte dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 15 Mar 2016 11:51:59 +0100
- Subject: Re: Building a cross-compiler for a Raspberry Pi
- Authentication-results: sourceware.org; auth=none
- References: <20160313060143 dot 4e5a89b4c428e989bc0351c9 at laposte dot net> <56E547C3 dot 7010009 at redhat dot com> <20160313135107 dot 9dd2c57c3831c19574de4a7b at laposte dot net> <56E690C1 dot 2060406 at redhat dot com>
These are the steps I follow in order to build a cross-compiler:
1) I build binutils for the target
2) I install the headers from a library (that is specific)
3) I build a minimal gcc for the target (only C language supported)
4) I build a library for the target (that is specific)
5) I build a full gcc for the target (C and C++ languages supported)
For the step 2), it must be skipped for some targets:
* If the target is avr, it must be skipped
* If the target is i686-w64-mingw32, it must be done
For the step 2) and 4), the library I use depends on the target:
* If the target is avr, I use avr-libc [1]
* If the target is i686-w64-mingw32, I use mingw-w64 [2]
This method works fine for avr and i686-w64-mingw32, so I am wondering why it does not work for my armv6l-unknown-linux-gnueabihf machine too.
I guess it is because I don't know which specific library I can use for the steps 2) and 4).
Maybe newlib [3] is what I am looking for.
Can you tell me if my method is correct and if newlib could be what I am looking for?
Thank you.
Best regards.
[1] http://www.nongnu.org/avr-libc/
[2] http://mingw-w64.org/
[3] https://sourceware.org/newlib/
On Mon, 14 Mar 2016 10:21:53 +0000
Andrew Haley <aph@redhat.com> wrote:
> On 13/03/16 12:51, YuGiOhJCJ Mailing-List wrote:
> >> On 13/03/16 05:01, YuGiOhJCJ Mailing-List wrote:
> >>> 1) How we determine the correct machine name?
> >>
> >> It looks correct.
> >>
> >
> > OK it is correct but how to know it is correct?
>
> Go to a Raspberry Pi and run config.guess.
>
> > I mean, I have chance to find people who have written articles where I can see the good machine name.
> > But alone, it is hard to guess.
> > I read [1] and it gives me the idea to use the config.guess script:
> > $ scp /usr/share/automake-1.11/config.guess root@raspberrypi:~/
> > root@raspberrypi's password:
> > config.guess 100% 44KB 43.8KB/s 00:00
> > $ ssh root@raspberrypi
> > root@raspberrypi's password:
> > Last login: Fri Jan 2 07:32:11 1970 from 192.168.0.6
> > Linux 4.1.19+.
> > $ ./config.guess
> > armv6l-unknown-linux-gnueabihf
> >
> > So, I think I could use this machine name too.
>
> I think you could too.
>
> > I don't like this solution with the config.guess script because it
> > supposes to have an access to the target system in order to run the
> > script on it.
>
> That's true. But you need access to the target system in order to be
> able to test a cross compiler, so it's not a big issue. It's obvious
> that you must be able to test a cross compiler after you build it.
>
> > Is there something (like a documentation) in the gcc source code
> > that helps to guess the best machine name for an ARMv6 CPU on Linux?
>
> I don't think so.
>
> >>> 2) How to build my cross-compiler without glibc?
> >>
> >> Copy the root filesystem from a Raspberry Pi onto your machine, then
> >> configure gcc with --sysroot=<dirname>, the RPi root filesystem. GCC
> >> will then pull all target headers and libraries from the sysroot.
> >
> > I prefer a solution that does not require to have an access to the
> > target machine. Also, I would like a solution that does not depend
> > on binaries if that's possible.
>
> It's not: you need to be able to link against the target's libraries.
> It's not just about libc: very few programs use only libc. This way,
> you have all of the target's libraries and header files.
>
> > Why the method for a Raspberry Pi cross-compiler is so different
> > from an i686-w64-mingw32 or avr cross-compiler please?
>
> It's the standard way for GNU/Linux cross-compilers. It's the best
> way, and the easiest. The other ways are inferior.
>
> Andrew.