Building gcc in cygwin for cross-compiling for MIPS linux

Programming, for all ages and all languages.
Post Reply
alikim
Posts: 3
Joined: Wed Sep 20, 2017 2:38 pm

Building gcc in cygwin for cross-compiling for MIPS linux

Post by alikim »

Hi,
I'm following the guide here http://wiki.osdev.org/GCC_Cross-Compiler, my target being

Code: Select all

mipsel-unknown-linux-gnu
and I'm stuck at

Code: Select all

make all-target-libgcc
which fails with

Code: Select all

In file included from ../../../gcc-7.2.0/libgcc/gthr.h:148:0,
                 from ../../../gcc-7.2.0/libgcc/libgcov-interface.c:27:
./gthr-default.h:35:10: fatal error: pthread.h: No such file or directory
 #include <pthread.h>
          ^~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:915: _gcov_dump.o] Error 1
make[1]: Leaving directory '/home/alikim/src/build-gcc/mipsel-unknown-linux-gnu/libgcc'
make: *** [Makefile:11866: all-target-libgcc] Error 2
What do I need to do to fix this error?

Also, since I'm not building a OS, just a program that needs to run under linux, will

Code: Select all

--without-headers
limit my ability to use standard C libraries in my code?

Thank you!
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Building gcc in cygwin for cross-compiling for MIPS linu

Post by Korona »

The wiki instructions are for building a freestanding compiler. If you want a hosted compiler, you'll need to build --with-sysroot and install the libc headers into the sysroot before building libgcc, libstdc++ and other GCC support libraries. You cannot use --without-headers and expect to use the C standard library.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
alikim
Posts: 3
Joined: Wed Sep 20, 2017 2:38 pm

Re: Building gcc in cygwin for cross-compiling for MIPS linu

Post by alikim »

I'm following the wiki instructions for building a freestanding compiler, it's not what I want but it's a start...

The point is, it doesn't work. I copied all the instructions from the wiki and it fails as I described above, I'd like to know why, that's my question.

As per wiki, binutils were compiled with --with-sysroot and gcc with --without-headers.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Building gcc in cygwin for cross-compiling for MIPS linu

Post by Korona »

Let me reiterate: You cannot build a Linux compiler --without-headers. You need to pass --with-sysroot to the GCC build and compile your libc to that directory (using your cross compiler, that was built during all-gcc), before building libgcc.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
alikim
Posts: 3
Joined: Wed Sep 20, 2017 2:38 pm

Re: Building gcc in cygwin for cross-compiling for MIPS linu

Post by alikim »

Oh god... I mean thank you!
lisanke
Posts: 1
Joined: Thu Nov 01, 2018 2:04 am
Libera.chat IRC: lisanke

Re: Building gcc in cygwin for cross-compiling for MIPS linu

Post by lisanke »

If, as was stated above, you can Not build a gcc cross-compiler --without-headers... Why does the https://wiki.osdev.org/GCC_Cross-Compiler#GCC Instructions for building a cross-compiler (target with no libc) have us try??? Just trying to understand... is it a right of passage? :-p I'm trying to build a cross compiler on a windows machine under cygwin and I can find pthread.h ... the make all-libgcc-target can't find it because we told configure to not find it... but the build abends. So, what I think is asked here and in many other places is, why would an instruction on building a GCC cross compiler intentional (or accidentally for years) produce an outcome know to fail? It makes no sense... I can move on to the next set with sysroot but I like to understand what went wrong when an expected outcome doesn't happen... after years of development, it's just my way.

Thanks to anyone with sincere comments that can explain.
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: Building gcc in cygwin for cross-compiling for MIPS linu

Post by linguofreak »

lisanke wrote:If, as was stated above, you can Not build a gcc cross-compiler --without-headers... Why does the https://wiki.osdev.org/GCC_Cross-Compiler#GCC Instructions for building a cross-compiler (target with no libc) have us try??? Just trying to understand... is it a right of passage? :-p I'm trying to build a cross compiler on a windows machine under cygwin and I can find pthread.h ... the make all-libgcc-target can't find it because we told configure to not find it... but the build abends. So, what I think is asked here and in many other places is, why would an instruction on building a GCC cross compiler intentional (or accidentally for years) produce an outcome know to fail? It makes no sense... I can move on to the next set with sysroot but I like to understand what went wrong when an expected outcome doesn't happen... after years of development, it's just my way.

Thanks to anyone with sincere comments that can explain.
It's not that you can't build a gcc cross-compiler --without-headers, it's that the wiki directions are for a different type of cross-compiler to be used for different purposes. The wiki directions are for building a cross compiler for kernel development, generally on the same architecture. The default configuration of gcc assumes that you are building applications that will be linked with a C library. To avoid certain pitfalls in kernel programming, you need to build a compiler that won't make those assumptions. But you're trying to build a cross compiler that will build Linux applications against glibc for MIPS on a different OS and architecture. For that, gcc needs to make all of the assumptions that the cross compiler setup on the wiki needs to avoid.

Korona didn't say you can't build a gcc *cross-compiler* --without-headers, he said that you can't build a *Linux compiler* without headers (strictly speaking, if you were building a compiler for an environment that used a Linux kernel, but where the system runtime was an oddball library that did not implement the C standard library, you would use --without-headers as well, but that doesn't really apply to what you're trying to do).
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: Building gcc in cygwin for cross-compiling for MIPS linu

Post by alexfru »

The latest MIPS toolchains are here.
Windows and Linux binaries, targeting Linux or bare metal.
Post Reply