How to Easily Build an Old GCC on Fedora 29
As a software developer, sometimes I need to build an older GCC. The reasons to build such a GCC may vary, from the old software to be built to the desktop OS which doesn't install the appropriate GCC toolchain. In my last case, it was the incompatibility between Fedora 29 which has the version 8.2.1 installed, and an open-source software module which needs CUDA 9.2 or 10.0.
For example, based on the official documentation, CUDA 10.0 supports only Fedora 27 with GCC 7.3.1. I don't want either to use a vritual machine nor to install Fedora 27 on my computer.
The CUDA development environment relies on tight integration with the host development environment, including the host compiler and C runtime libraries, and is therefore only supported on distribution versions that have been qualified for this CUDA Toolkit release.
Additionally, installing the older GCC version on Fedora 29 is not supported by the
dnf package manager. Even though I can download and build my own GCC, it can cause many conflicts in the system. Luckily, Bob Steagall has done a wonderful work that makes my life and probably other C/C++ software developers easier. He has published an article about how to build your own GCC on Linux and its Github Repository. He wrote the documentation in detail and even some scripts to make the whole process much easier.
However, after trying his step-by-step tutorial to install the gcc 7.3.0, I encountered a problem which I had to consult with him. Therefore, I would like to share this problem.
My first issue was this error message after during the compilation in multi-process mode with
libtool: compile: $HOME/Apps/gcc-builder/gcc-7.3.0-build/./gcc/xgcc -shared-libgcc -B$HOME/Apps/gcc-builder/gcc-7.3.0-build/./gcc -nostdinc++ ..... ../libstdc++-v3/libsupc++ -std=gnu++11 -DSANITIZER_LIBBACKTRACE -DSANITIZER_CP_DEMANGLE -I $HOME/Apps/gcc-builder/gcc-7.3.0/libsanitizer/../libbacktrace -I ../libbacktrace -I $HOME/Apps/gcc-builder/gcc-7.3.0/libsanitizer/../include -include $HOME/Apps/gcc-builder/gcc-7.3.0/libsanitizer/libbacktrace/backtrace-rename.h -g -O2 -D_GNU_SOURCE -MT sanitizer_platform_limits_posix.lo -MD -MP -MF .deps/sanitizer_platform_limits_posix.Tpo -c $HOME/Apps/gcc-builder/gcc-7.3.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc -fPIC -DPIC -o .libs/sanitizer_platform_limits_posix.o $HOME/Apps/gcc-builder/gcc-7.3.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc:157:10: fatal error: sys/ustat.h: No such file or directory #include <sys/ustat.h> ^~~~~~~~~~~~~ compilation terminated.
Due to the multi-process compilation, it was not easy to find the error. It is recommended to check the log file, instead of looking for the error on the console. In order to fix this error I did these two steps:
- remove the included header in the line 157,
remove its usage in the line 250 which contains this code:
unsigned struct_ustat_sz = sizeof(struct ustat);
Afterward, the build was successful and I can find my gcc under the folder /usr/local/gcc/.
With these commands, I can switch the GCC version in my Fedora 29 very easily and problem-free. To set the installed GCC 7.3.0, run:
and to restore the default GCC, run:
Since I start my application pretty often, I want to set my GCC version as default to be the version 7.3.0. Thus, I copied the command
source /usr/local/bin/setenv-for-gcc730.sh to the ~/.bashrc file.
I hope those two small fixes can help others who encounter the same issue. Many thanks to Bob Steagall for his article and tutorial.