I need an older version of GCC for installing CUDA toolkit, as CUDA toolkit does not support GCC newer than 5.3.1, and the Fedora machine I am trying to install it on comes with GCC 6. I don't have much control over the machine, so I have had to resort to building GCC myself. The steps I have followed are:
$ cd gcc-5.3.0
$ contrib/download_prerequisites
$ cd ../build
$ ../gcc-5.3.0/configure --prefix=$HOME/local/gcc-5.3.0 --program-suffix=5.3 --enable-shared --enable-multiarch --enable-threads=posix --enable-languages=c,c++,fortran --enable-checking=release --with-tune=generic
$ make
This results in successful configure, but make fails with error:
cfns.gperf:101:1: error: ‘const char* libc_name_p(const char*, unsigned int)’ redeclared inline with ‘gnu_inline’ attribute
There are a whole bunch of other C++11 warnings as well. After some google searches, I figured that this had to do with building GCC 5 or older with GCC 6. I thought it might help if I could force the compiler to follow C++98 instead. So, I tried:
$ export CXXFLAGS="-std=gnu++98"
$ ../gcc-5.3.0/configure ...
$ make
Didn't work. I still keep getting the same C++11 warnings, with build failing with the exact same error. Then, I tried:
$ ../gcc-5.3.0/configure CXXFLAGS="-std=gnu++98" ...
$ make
Again, same error. I peeked at the Makefile this time, and it sure had CXXFLAGS set to -std=gnu++98 here and there. Also, I have tried to build GCC 4.9.3 as well to see if this is a problem tied to a specific release, but I got the same error again.
I am not sure how to proceed further. Any help is much appreciated. Thanks.
1 Answer 1
In case someone else had this problem, apparently it's fixed by this patch. If you make the suggested changes (which would be too verbose to mention here, but are simple enough to be done manually) to the GCC source files, then configure and make successfully work without the need to pass -std options. I successfully built GCC 5.3.0 using GCC 6.2.1 with these changes to the source files.
4 Comments
In file included from ../.././gcc/cp/except.c:1023:0: ../.././gcc/cp/cfns.h:31:9: error: "cfns" is not a valid filename #line 3 cfns.gperf". Is it possible to build older gcc(5.3.1) using higher verssion(7)
gnu_inlineis a gcc extension to pre-c99 C code. Since you have the source code, you can locate the file that causes the error and try to change the offending declaration toinlineso that it follows the C99/11 and C++ syntax, or to__INLINEor__inline__. My guess is, your C++ code includes some headers written for pre-C99 c code. More info here: gcc.gnu.org/ml/gcc-patches/2015-08/msg00375.htmlgcc-5.3.0/gcc/cp/except.c:1043: undefined reference to `libc_name_p(char const*, unsigned int)' collect2: error: ld returned 1 exit status.