Building a cross-compiling gcc using wiki tutorial

Programming, for all ages and all languages.
Post Reply
User avatar
LB
Posts: 5
Joined: Tue Oct 22, 2013 10:12 am
Location: Richardson, Texas, North America
Contact:

Building a cross-compiling gcc using wiki tutorial

Post by LB »

Hi, I've been busy build a cross-compiler for the arm-none-eabi target, and I've been following this tutorial:
http://wiki.osdev.org/GCC_Cross-Compiler
My OS is Windows 7 64-bit and my compiler is nuwen MinGW 4.8.1

I've encountered many issues, but so far I have been able to solve all of them myself through the use of Google.

However, Google doesn't seem to be able to help me today - I'm encountering a strange problem with the cpp executable that was built.

I am using Cygwin+MinGW to build everything, which is working because I have a symbolic link from C:/cygwin/c/Users to C:/Users to allow tools that don't understand cygwin paths to still work properly. I've been able to build and install all the prerequisites for gcc as the tutorial requires (binutils, GMP, MPFR, MPC).

In my gcc directory I have a 'build' folder and an 'installation' folder. From the build folder I ran configure like this:

Code: Select all

../configure --target=$TARGET --prefix=/cygdrive/c/Users/Nicholas/Code/gcc-4.8.2/installation --disable-nls --enable-languages=c,c++ --without-headers
After resolving some issues via Google, I am now encountering this problem:

Code: Select all

checking how to run the C preprocessor... /lib/cpp
configure: error: in `/cygdrive/c/Users/Nicholas/Code/gcc-4.8.2/build/arm-none-eabi/libgcc':
configure: error: C preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details.
make[1]: *** [configure-target-libgcc] Error 1
make[1]: Leaving directory `C:/Users/Nicholas/Code/gcc-4.8.2/build'
make: *** [all] Error 2
I've put the relevant config.log on gist:
https://gist.github.com/LB--/22b8c7755f913ee7c173
The relevant line from the output is line 747.

I'm really confused as to what is happening here. Google searching some of the errors gives me relevant results but none of them have solutions that I can use or that apply to me.

What I think is happening is that it is trying to run test the preprocessor on test files which include simple common headers that should exist. What I don't understand is why it is doing this, I thought that the configuration setting --without-headers affected things like this?

On the wiki, I see a troubleshooting topic "C++ preprocessor "/lib/cpp" fails sanity check in Cygwin when building Binutils", but I am not building binutils - I have built binutils already and it works. I'm having this issue with building gcc.

I really don't know what to do here - nothing I can find on Google helps, and all the workarounds I guessed and tried didn't work. Has anyone else had this problem and solved it? I've put a lot of time and effort into this build and I'm not willing to just give up.
Everything compiles on *nix, everything executes on Windows, and any contradiction to these rules is magic.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Building a cross-compiling gcc using wiki tutorial

Post by sortie »

Okay, a random guess is that the CPP variable is set to /lib/cpp in your normal cygwin environment. Could you run 'env' in your shell and verify nothing trouble-some is there, and if you don't see any, then please upload it here? Otherwise, your PATH is complex, it may have picked up something bad there.

Oh, I missed that you disregard the Wiki advise. Please "In Cygwin's installer, you need to separately select the gcc4-core and gcc4-g++ packages for proper configuration of the host compiler." (whatever that means, I don't use cygwin).
User avatar
LB
Posts: 5
Joined: Tue Oct 22, 2013 10:12 am
Location: Richardson, Texas, North America
Contact:

Re: Building a cross-compiling gcc using wiki tutorial

Post by LB »

sortie wrote:Okay, a random guess is that the CPP variable is set to /lib/cpp in your normal cygwin environment. Could you run 'env' in your shell and verify nothing trouble-some is there, and if you don't see any, then please upload it here? Otherwise, your PATH is complex, it may have picked up something bad there.
https://gist.github.com/LB--/a8f8212e362da0cc4ef6
sortie wrote:Oh, I missed that you disregard the Wiki advise. Please "In Cygwin's installer, you need to separately select the gcc4-core and gcc4-g++ packages for proper configuration of the host compiler." (whatever that means, I don't use cygwin).
I'll try reinstalling Cygwin - I installed it several months ago.

EDIT: I've just tried reinstalling Cygwin and I am starting my gcc build from scratch. No sign of the option in cygwin's setup that the wiki mentions. I think the issue before was that the detected --build and --host were wrong, so I am now explicitly specifying them:

Code: Select all

../configure --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=arm-none-eabi --prefix=/cygdrive/c/cross/arm-none-eabi/gcc --disable-nls --enable-languages=c,c++ --without-headers --enable-static --disable-shared
Everything compiles on *nix, everything executes on Windows, and any contradiction to these rules is magic.
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Building a cross-compiling gcc using wiki tutorial

Post by sortie »

Wait - you are using MinGW from Cygwin?

I have the feeling that's just bad. Try use a pure Cygwin without any MinGW parts - or better yet - a real Unix system.
User avatar
LB
Posts: 5
Joined: Tue Oct 22, 2013 10:12 am
Location: Richardson, Texas, North America
Contact:

Re: Building a cross-compiling gcc using wiki tutorial

Post by LB »

Everything goes smoothly until this part, which as before I honestly have no idea how to fix (nor how to investigate):

Code: Select all

make[2]: Leaving directory `C:/Users/Nicholas/Code/gcc-trunk/build/gcc'
Checking multilib configuration for libgcc...
/usr/bin/sh: -c: line 4: unexpected EOF while looking for matching `''
/usr/bin/sh: -c: line 5: syntax error: unexpected end of file
make[1]: *** [all-target-libgcc] Error 1
make[1]: Leaving directory `C:/Users/Nicholas/Code/gcc-trunk/build'
make: *** [all] Error 2
Note that "make all-gcc" works fine, I only get this with "make" or "make all-target-libgcc"
Everything compiles on *nix, everything executes on Windows, and any contradiction to these rules is magic.
User avatar
LB
Posts: 5
Joined: Tue Oct 22, 2013 10:12 am
Location: Richardson, Texas, North America
Contact:

Re: Building a cross-compiling gcc using wiki tutorial

Post by LB »

OK, so I gave in and am now running on Linux Mint via VirtualBox. The same general thing happens as on Windows - it builds gcc and then fails with libgcc. This time the failure error message is different:

Code: Select all

/home/adminuser/Desktop/Code/gcc-64/./gcc/xgcc -B/home/adminuser/Desktop/Code/gcc-64/./gcc/ -L/usr/local/x86_64-w64-mingw32/lib -L/usr/local/mingw/lib -isystem /usr/local/x86_64-w64-mingw32/include -isystem /usr/local/mingw/include -B/usr/local/x86_64-w64-mingw32/bin/ -B/usr/local/x86_64-w64-mingw32/lib/ -isystem /usr/local/x86_64-w64-mingw32/include -isystem /usr/local/x86_64-w64-mingw32/sys-include    -g -O2 -m32 -O2  -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -DNATIVE_CROSS  -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include   -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector   -I. -I. -I../../.././gcc -I../../../../gcc-4.8.2/libgcc -I../../../../gcc-4.8.2/libgcc/. -I../../../../gcc-4.8.2/libgcc/../gcc -I../../../../gcc-4.8.2/libgcc/../include -I../../../../gcc-4.8.2/libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS -DUSE_EMUTLS -o _muldi3.o -MT _muldi3.o -MD -MP -MF _muldi3.dep -DL_muldi3 -c ../../../../gcc-4.8.2/libgcc/libgcc2.c 
In file included from ../../../../gcc-4.8.2/libgcc/../gcc/tsystem.h:44:0,
                 from ../../../../gcc-4.8.2/libgcc/libgcc2.c:27:
/home/adminuser/Desktop/Code/gcc-64/gcc/include/stddef.h:1:25: fatal error: stddef.h: No such file or directory
 #include_next <stddef.h>
                         ^
compilation terminated.
Note that I am first building to target x86_64-W64-mingw32 so that I can cross compile for windows, because I want the arm-none-eabi compiler to run on windows. I get the same problem if I compile to directly target arm-none-eabi, though. This is my configure:

Code: Select all

../gcc-4.8.2/configure --build=i386-linux-gnu --host=i386-linux-gnu --target=x86_64-w64-mingw32 --enable-languages=c,c++ --disable-nls --enable-static --disable-shared
I originally tired --without-headers as suggested by the tutorial, but that has exactly the same result.
Everything compiles on *nix, everything executes on Windows, and any contradiction to these rules is magic.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Building a cross-compiling gcc using wiki tutorial

Post by AJ »

Hi,

You don't need Mingw for this - use Cygwin's own GCC (gcc-core).

Cheers,
Adam
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Building a cross-compiling gcc using wiki tutorial

Post by sortie »

So, you want to:

1) On a 32-bit Linux machine (--build=i386-linux-gnu)
2) Build a compiler that runs on 64-bit Windows (--host=x86_64-w64-mingw32)
3) Which produces executables for ARM (--target=arm-none-eabi)

This is insanity. If you are willing to use a Linux system, just use that for development. This Canadian cross is, however, entirely possible if you use the build, host and target option as I gave them above (or what is appropriate in your exact context). Note that you will likely need to build a cross-compiler (build=i386-linux-gnu, host=i386-linux-gnu, target=x86_64-w64-mingw32 - or what is appropriate for you) that cross-compiles to Windows. Next you'll need to install development headers and libraries (such as MinGW) into a system root such that you can produce Windows executables. Note that some distroes actually includes MinGW such that you can cross-compile to Windows using a distribution package. You should probably use that.
User avatar
LB
Posts: 5
Joined: Tue Oct 22, 2013 10:12 am
Location: Richardson, Texas, North America
Contact:

Re: Building a cross-compiling gcc using wiki tutorial

Post by LB »

Thanks, I knew what each of the build, host, and target parameters would need to be. The windows -> arm-none-eabi compiler is not for me, so my preferred development environment is out of the question.

The information I was missing that you provided was that I needed to install the headers to cross compile for windows - I'll look into that.
Everything compiles on *nix, everything executes on Windows, and any contradiction to these rules is magic.
Post Reply