Last active
March 2, 2025 08:35
-
-
Save dstrebkov/ebe070c1e35d94f859c6cacae8d642ef to your computer and use it in GitHub Desktop.
GCC 12 or GCC 13 install from sources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ######################################################################################## | |
| # GCC 12 and GCC 13 installer: | |
| # - checks out GCC sources from official GCC Git repo; | |
| # - builds them and installs GCC binaries to $HOME/opt/gcc-x.y.z location | |
| # | |
| # Installed languages are: C/C++, Fortran and Go | |
| # | |
| # Prerequisites: Flex version 2.5.4 (or later) and tools & packages listed in | |
| # https://gcc.gnu.org/install/prerequisites.html | |
| # | |
| ######################################################################################## | |
| read -p "Enter GCC version to install ('12' or '13' are supported): " GCC_MAJOR_VERSION | |
| if ! ( [ $GCC_MAJOR_VERSION -eq 12 ] || [ $GCC_MAJOR_VERSION -eq 13 ] ); then | |
| echo "Unsupported version provided, exiting..." | |
| exit 1 | |
| fi | |
| GCC_CHECKOUT_DIR_NAME=gcc-source | |
| git clone https://gcc.gnu.org/git/gcc.git ./$GCC_CHECKOUT_DIR_NAME/ | |
| cd $GCC_CHECKOUT_DIR_NAME/ | |
| case $GCC_MAJOR_VERSION in | |
| 12) | |
| ENABLED_LANGUAGES=c,c++,fortran,go | |
| git checkout remotes/origin/releases/gcc-12 | |
| ;; | |
| 13) | |
| ENABLED_LANGUAGES=c,c++,fortran,go | |
| git checkout remotes/origin/releases/gcc-13 | |
| ;; | |
| esac | |
| ./contrib/download_prerequisites | |
| GCC_FULL_VERSION=$(head -n 1 ./gcc/BASE-VER) | |
| echo "===================================================================================================" | |
| echo "Installing GCC $GCC_MAJOR_VERSION ($GCC_FULL_VERSION) with enabled languages: $ENABLED_LANGUAGES..." | |
| echo "===================================================================================================" | |
| read -rsp $'Press enter to continue...\n' | |
| cd .. | |
| mkdir ./gcc-$GCC_MAJOR_VERSION-build | |
| cd gcc-$GCC_MAJOR_VERSION-build/ | |
| # Installing GCC into $HOME/opt/gcc-x.y.z is normally a good idea. | |
| # To install it globally, installing into /usr/local/gcc-x.y.z is normally a good idea. | |
| $PWD/../$GCC_CHECKOUT_DIR_NAME/configure --prefix=$HOME/opt/gcc-$GCC_FULL_VERSION --enable-languages=$ENABLED_LANGUAGES --disable-multilib | |
| # Next one might take up to 3.5 hours in case of GCC 13 | |
| make -j 16 | |
| make install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I failed... I did the compilation on the ARM platform (orangepi/ubuntu), unfortunately it is an old version of ubuntu (xenial) and therefore there is no newer version of GCC. At the end I got an error:
-o build/gengtype-lex.o gengtype-lex.cc g++: error: gengtype-lex.cc: Nie ma takiego pliku ani katalogu g++: fatal error: no input files compilation terminated. Makefile:2823: polecenia dla obiektu 'build/gengtype-lex.o' nie powiodły się make[3]: *** [build/gengtype-lex.o] Błąd 1 make[3]: *** Oczekiwanie na niezakończone zadania.... /bin/bash /root/gcc-12-build/../gcc-source/gcc/../move-if-change tmp-arm-cpu-cdata.h arm-cpu-cdata.h echo timestamp > s-arm-cdata /bin/bash /root/gcc-12-build/../gcc-source/gcc/../move-if-change tmp-optionlist optionlist echo timestamp > s-options rm fsf-funding.pod lto-dump.pod gfdl.pod gpl.pod cpp.pod gcc.pod gcov-dump.pod gcov-tool.pod gcov.pod make[3]: Opuszczenie katalogu '/root/gcc-12-build/gcc' Makefile:4970: polecenia dla obiektu 'all-stage1-gcc' nie powiodły się make[2]: *** [all-stage1-gcc] Błąd 2 make[2]: Opuszczenie katalogu '/root/gcc-12-build' Makefile:31252: polecenia dla obiektu 'stage1-bubble' nie powiodły się make[1]: *** [stage1-bubble] Błąd 2 make[1]: Opuszczenie katalogu '/root/gcc-12-build' Makefile:1079: polecenia dla obiektu 'all' nie powiodły się make: *** [all] Błąd 2 make[1]: Wejście do katalogu '/root/gcc-12-build' /bin/bash /root/gcc-12-build/../gcc-source/mkinstalldirs /root/opt/gcc-12.4.1 /root/opt/gcc-12.4.1 mkdir -p -- /root/opt/gcc-12.4.1 /root/opt/gcc-12.4.1 make[2]: Wejście do katalogu '/root/gcc-12-build/fixincludes' make[2]: *** Brak reguł do wykonania obiektu 'install'. Stop. make[2]: Opuszczenie katalogu '/root/gcc-12-build/fixincludes' Makefile:4097: polecenia dla obiektu 'install-fixincludes' nie powiodły się make[1]: *** [install-fixincludes] Błąd 2 make[1]: Opuszczenie katalogu '/root/gcc-12-build' Makefile:2624: polecenia dla obiektu 'install' nie powiodły się make: *** [install] Błąd 2maybe my platform is too weak and has too little RAM (512) for compilation to succeed :-(
I increased the swap file memory to 1GB, installed some libraries and the compilation started but I have another error and I probably have to abandon the compilation. :-(
regards
https://gibsonic.org/tools/2019/08/08/gcc_building.html
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04