0

A shell script to download packages for, configure, build and install a GCC cros...

 1 month ago
source link: https://gist.github.com/preshing/41d5c7248dea16238b60
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

A shell script to download packages for, configure, build and install a GCC cross-compiler. · GitHub

Instantly share code, notes, and snippets.

A shell script to download packages for, configure, build and install a GCC cross-compiler.

thanks

Thank you!!!

How to build the cross compiler for x86_64?

I changed TARGET to "x86_64-linux-gnu", and LINUX_ARCH to "x86_64" in the script, but I got the follow error at the stage building glibc:

x86_64-linux-gnu-gcc -D_RPC_THREAD_SAFE_ -D_GNU_SOURCE -DIS_IN_build -include /net/ala-rsubbian-lx1/ala-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/build-glibc/c
onfig.h rpc_main.c
-o /net/ala-rsubbian-lx1/ala-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/build-glibc/sunrpc/cross-rpc_main.o -MMD -MP -MF /net/ala-rsubbian-lx1/ala
-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/build-glibc/sunrpc/cross-rpc_main.o.dt -MT /net/ala-rsubbian-lx1/ala-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/build
-glibc/sunrpc/cross-rpc_main.o -c
In file included from /net/ala-rsubbian-lx1/ala-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/opt/cross/x86_64-linux-gnu/include/errno.h:28:0,
from rpc_main.c:37:
/net/ala-rsubbian-lx1/ala-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/opt/cross/x86_64-linux-gnu/include/features.h:389:23: fatal error: gnu/stubs.h: No such file
or directory
#include <gnu/stubs.h>
^
compilation terminated.
make[2]: *** [/net/ala-rsubbian-lx1/ala-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/build-glibc/sunrpc/cross-rpc_main.o] Error 1
make[2]: Leaving directory /net/ala-rsubbian-lx1/ala-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/glibc-2.20/sunrpc' make[1]: *** [sunrpc/install-headers] Error 2 make[1]: Leaving directory/net/ala-rsubbian-lx1/ala-rsubbian-lx11/bpang/SHARE/GCC520/GIT/x86_64/glibc-2.20'
make: *** [install-headers] Error 2

Is there a version to build gcc 5.3.x?

used this guide to compile GCC 6.1 with latest GLibc and 4.6 Kernel , thank you for your efforts

pwaring commented on May 18, 2016

edited

@Vladinator You should be able to build 5.3.x with this. If not, I've created a similar script with slightly higher levels of abstraction which definitely builds GCC 4.9.x, 5.3.x and 6.1: https://github.com/pwaring/gcc-cross-compiler

Thanks @pwaring, maybe you can add a note at the top of your blog post for the github repository?

mdeguzis commented on Jul 23, 2016

edited

Anyone get this to build fine on amd64? @pwaring, I don't see support for amd64 in that, is it possible?

My current version of this script with some improvements:
https://github.com/ProfessorKaos64/LibreGeek-Packaging/blob/brewmaster/gcc/build-cross-gcc.sh

@BaoshanPang - my version of this script above seems to work until a point:

a - /home/desktop/build-cross-gcc/build-glibc/string/rtld-cacheinfo.os
a - /home/desktop/build-cross-gcc/build-glibc/time/rtld-setitimer.os
mv -f /home/desktop/build-cross-gcc/build-glibc/elf/rtld-libc.aT /home/desktop/build-cross-gcc/build-glibc/elf/rtld-libc.a
make[3]: Leaving directory '/home/desktop/build-cross-gcc/glibc-2.23/elf'
make[2]: Leaving directory '/home/desktop/build-cross-gcc/glibc-2.23/elf'
Makefile:214: recipe for target 'elf/subdir_lib' failed
make[1]: *** [elf/subdir_lib] Error 2
make[1]: Leaving directory '/home/desktop/build-cross-gcc/glibc-2.23'
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 2
FAILED COMMAND: sudo make $PARALLEL_MAKE

@thijstriemstra The blog post you link to isn't mine so I can't edit it.

I am also facing same issue like...

make[4]: *** [subsegs.o] Error 1
make[4]: *** Waiting for unfinished jobs....
mv -f .deps/stabs.Tpo .deps/stabs.Po
mv -f .deps/symbols.Tpo .deps/symbols.Po
mv -f .deps/read.Tpo .deps/read.Po
make[4]: Leaving directory '/home/esmadmin/Final_code/port_code/Updates/build_cross_gcc/cross_compilation/build-binutils/gas'
Makefile:2165: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory '/home/esmadmin/Final_code/port_code/Updates/build_cross_gcc/cross_compilation/build-binutils/gas'
Makefile:682: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/home/esmadmin/Final_code/port_code/Updates/build_cross_gcc/cross_compilation/build-binutils/gas'
Makefile:4710: recipe for target 'all-gas' failed
make[1]: *** [all-gas] Error 2
make[1]: Leaving directory '/home/esmadmin/Final_code/port_code/Updates/build_cross_gcc/cross_compilation/build-binutils'
Makefile:830: recipe for target 'all' failed
make: *** [all] Error 2
FAILED COMMAND: make $PARALLEL_MAKE

I have issue with PATH_MAX undefined while compiling last part of gcc (part6)

...
libtool: compile:  /rtos/test/build-gcc/./gcc/xgcc -B/rtos/test/build-gcc/./gcc/ -B/rtos/cross/x86_64-artos-linux/bin/ -B/rtos/cross/x86_64-artos-linux/lib/ -isystem /rtos/cross/x86_64-artos-linux/include -isystem /rtos/cross/x86_64-artos-linux/sys-include -DHAVE_CONFIG_H -I. -I../../../../gcc-6.2.0/libmpx/mpxrt -I.. -I../../../../gcc-6.2.0/libmpx/.. -fPIC -g -O2 -c ../../../../gcc-6.2.0/libmpx/mpxrt/mpxrt-utils.c  -fPIC -DPIC -o .libs/libmpx_la-mpxrt-utils.o
../../../../gcc-6.2.0/libmpx/mpxrt/mpxrt-utils.c:69:23: error: 'PATH_MAX' undeclared here (not in a function)
 #define MAX_FILE_NAME PATH_MAX
                       ^
../../../../gcc-6.2.0/libmpx/mpxrt/mpxrt-utils.c:91:22: note: in expansion of macro 'MAX_FILE_NAME'
 static char out_name[MAX_FILE_NAME];
                      ^~~~~~~~~~~~~
Makefile:390: recipe for target 'libmpx_la-mpxrt-utils.lo' failed
make[4]: *** [libmpx_la-mpxrt-utils.lo] Error 1
make[4]: Leaving directory '/rtos/test/build-gcc/x86_64-artos-linux/libmpx/mpxrt'
Makefile:409: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory '/rtos/test/build-gcc/x86_64-artos-linux/libmpx'
Makefile:300: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/rtos/test/build-gcc/x86_64-artos-linux/libmpx'
Makefile:12473: recipe for target 'all-target-libmpx' failed
make[1]: *** [all-target-libmpx] Error 2
...

my configuration are :

LINUX_ARCH=x86_64
CONFIGURATION_OPTIONS="--disable-multilib --disable-nls --disable-doc --without-selinux --disable-debug --disable-valgrind-tests --disable-documentation --disable-gtk-doc-pdf --disable-gtk-doc --disable-manpages --disable-gtk-doc-html --disable-tests" #
PARALLEL_MAKE=-j4
BINUTILS_VERSION=binutils-2.27
GCC_VERSION=gcc-6.2.0
LINUX_KERNEL_VERSION=linux-4.8.1
GLIBC_VERSION=glibc-2.24
MPFR_VERSION=mpfr-3.1.5
GMP_VERSION=gmp-6.1.1
MPC_VERSION=mpc-1.0.3
ISL_VERSION=isl-0.17.1
CLOOG_VERSION=cloog-0.18.4

any hints to fix?

How to make it works with "arm android"?

Nice script! Just had to change a few things to build a gcc cross compiler for mips.

bembam commented on Apr 9, 2017

edited

I am facing the following error after make -j4:

cc1: all warnings being treated as errors
Makefile:891: recipe for target 'subsegs.o' failed
make[4]: *** [subsegs.o] Error 1
make[4]: *** Waiting for unfinished jobs....
mv -f .deps/stabs.Tpo .deps/stabs.Po
mv -f .deps/read.Tpo .deps/read.Po
mv -f .deps/symbols.Tpo .deps/symbols.Po
make[4]: Leaving directory '/home/bem/Desktop/crosscompiler/build-binutils/gas'
Makefile:2165: recipe for target 'all-recursive' failed
make[3]: *** [all-recursive] Error 1
make[3]: Leaving directory '/home/bem/Desktop/crosscompiler/build-binutils/gas'
Makefile:682: recipe for target 'all' failed
make[2]: *** [all] Error 2
make[2]: Leaving directory '/home/bem/Desktop/crosscompiler/build-binutils/gas'
Makefile:4710: recipe for target 'all-gas' failed
make[1]: *** [all-gas] Error 2
make[1]: Leaving directory '/home/bem/Desktop/crosscompiler/build-binutils'
Makefile:830: recipe for target 'all' failed
make: *** [all] Error 2

U007D commented on May 6, 2017

edited

I'm building for a RaspberryPi3 running Raspbian, so I want to build my cross-compiler for a 32-bit Linux target. (I'm on Mac OS X Sierra 10.12.4, if that matters.) Should I use arm-linux? armv7-unknown-gnueabihf? Something else?

Fairly new to this, so in addition to knowing the proper 32-bit target identifier for the RPi3, I'd like to know how/where to find the list of valid targets.

Thank you for this and the blog article!

U007D commented on May 6, 2017

edited

Incidentally I'm here looking at the script, because in following the steps on your blog, I got an error on Step 4.

I'm on Mac OS X Sierra 10.12.4. No errors (modulo having to unpack linux-4.4.38 to a case-sensitive filesystem in order for it to install properly) following Steps 1-3.

At Step 4, though, I got the following:

$ ../glibc-2.19/configure --prefix=/usr/local/bin/gcc-7.1.0-armv7-linux-gnueabihf/armv7-linux-gnueabihf --build=$MACHTYPE --host=armv7-linux-gnueabihf --target=armv7-linux-gnueabihf --with-headers=/usr/local/bin/gcc-7.1.0-armv7-linux-gnueabihf/include --disable-multilib libc_cv_forced_unwind=yes
checking build system type... x86_64-apple-darwin16
checking host system type... armv7-unknown-linux-gnueabihf
checking for armv7-linux-gnueabihf-gcc... /usr/local/bin/gcc-7.1.0-armv7-linux-gnueabihf/bin/armv7-linux-gnueabihf-gcc
...
checking whether to put _rtld_local into .sdata section... no
checking for .preinit_array/.init_array/.fini_array support... no
configure: error: Need linker with .init_array/.fini_array support.

I've tried several Google searches and a number of variations of the above configure command, but no luck.

Any ideas on how to fix this?

Some background, in case it helps:

  • Followed steps 1-4 exactly, changing only the target (armv7-unknown-gnueabihf for 32-bit ARM) and the install path (/usr/local/bin/gcc-7.1.0-armv7-unknown-gnueabihf).
  • Compiled using gcc v7.1.0 using the following versions of the gcc components to best match the kernel version used for the Raspberry Pi 3's Raspbian Linux or otherwise used the latest version:
    • binutils v2.28
    • glibc v2.19
    • gmp v6.1.2
    • isl v0.16.1
    • linux 4.4.38
    • mpc v1.0.3
    • mpfr v3.1.5

ghost commented on Dec 30, 2017

edited by ghost

Disable libsanitizer by passing --disable-libsanitizer to GCC while configuring. That is, if you're using uClibc-ng.

If you want to compile on macOS do a Canadian Cross Compile with a macOS to Linux ABI handover. I'm not sure how to explain.

kanj commented on Apr 3, 2018

Amazing script. I was able to create a cross compiler for ARM, and then create a Kernel and BusyBox to boot up in QEMU. I have converted the script to a makefile under kanj/MAKE_CROSS_LINUX for reference.

Very interesting script. On this basis, i create conan package https://github.com/BetterCallBene/conan-cgcc.

Is it possible to build multi lib gcc i.e. with aarch64 and arm?

This doesn't work for me trying to build gcc-4.8.5. It fails on configuring glibc (2.12.2) as it is using the newly built cross-compiled-gcc which cannot find stdio.h. I can resolve this by not exporting the PATH to the new binaries but then the csu binaries built will be for the host architecture. Not really sure how to resolve it.

stahta01 commented on Aug 8, 2020

edited

Anyone trying to use something other than Linux as the build/host platform may be helped by looking at my fork of this script.
My Fork

I used MSys2 64 bit (a Cygwin fork) under Win7 64 bit; I yet to test the cross compiler produced; did it as a learning exercise.
I have no need to use it; but, likely will in a few months.

Edit2: Once, I deleted the installed files my version of the script stopped building with gcc/glibc errors.

Tim S.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK