4

I'm using Arch linux and I need GCC 4.7.0 for a class.

I only have GCC 6.2.1 installed on my system currently.

I followed all the install instructions correctly but I still yield this error after running the initial make.

$ make
.
.
In file included from /home/flounder/src/gcc-4.7.0/gcc-4.7.0/gcc/cp/except.c:987:0:
cfns.gperf: At top level:
cfns.gperf:101:1: error: ‘gnu_inline’ attribute present on ‘libc_name_p’
cfns.gperf:26:14: error: but not here
.
.
make[3]: *** [Makefile:1055: cp/except.o] Error 1
make[3]: Leaving directory '/home/flounder/src/gcc_compile/gcc'
make[2]: *** [Makefile:4101: all-stage1-gcc] Error 2
make[2]: Leaving directory '/home/flounder/src/gcc_compile'
make[1]: *** [Makefile:19342: stage1-bubble] Error 2
make[1]: Leaving directory '/home/flounder/src/gcc_compile'
make: *** [Makefile:898: all] Error 2

I've read that this can happen when trying to build old versions of GCC with modern versions because:

GCC adds new errors as versions go on, so the source code of older versions of GCC isn't always considered valid under newer versions of GCC

I read that here, here, and here.

So what can I do to remedy the issue?

Two possible solutions I think could work:

  1. Cross compile GCC 4.7.0 for my computer using the school Linux computers (which also have GCC 4.7.0 but they're 32-bit and I have a 64-bit OS)
  2. First compile GCC 5.4.x on my computer using GCC 6.2.1 then use GCC 5.4.x to compile GCC 4.7.0

The first option seems more bulletproof. Would they both work? Is one better than the other?

Edit:

As @Kenneth B. Jensen mentioned below, I attempted to run the configuration with the --disable-werror flag set and attempted to run the initial make with the -k flag set but I still ran into trouble. The following is the error output:

$ make -k
.
.
.
if [ xinfo = xinfo ]; then \
    makeinfo --split-size=5000000 --split-size=5000000 --split-size=5000000 --no-split -I . -I /home/flounder/src/gcc-4.7.0/gcc/doc \
            -I /home/flounder/src/gcc-4.7.0/gcc/doc/include -o doc/cppinternals.info /home/flounder/src/gcc-4.7.0/gcc/doc/cppinternals.texi; \
fi
echo timestamp > gcc.pod
perl /home/flounder/src/gcc-4.7.0/gcc/../contrib/texi2pod.pl /home/flounder/src/gcc-4.7.0/gcc/doc/invoke.texi > gcc.pod
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/^\@strong{ <-- HERE (.*)}$/ at /home/flounder/src/gcc-4.7.0/gcc/../contrib/texi2pod.pl line 319.
echo timestamp > doc/gcc.1
(pod2man --center="GNU" --release="gcc-4.7.0" --date=2012-03-22 --section=1 gcc.pod > doc/gcc.1.T$$ && \
    mv -f doc/gcc.1.T$$ doc/gcc.1) || \
    (rm -f doc/gcc.1.T$$ && exit 1)
echo timestamp > gpl.pod
perl /home/flounder/src/gcc-4.7.0/gcc/../contrib/texi2pod.pl /home/flounder/src/gcc-4.7.0/gcc/doc/include/gpl_v3.texi > gpl.pod
Unescaped left brace in regex is deprecated, passed through in regex; marked by <-- HERE in m/^\@strong{ <-- HERE (.*)}$/ at /home/flounder/src/gcc-4.7.0/gcc/../contrib/texi2pod.pl line 319.
echo timestamp > doc/gpl.7
(pod2man --center="GNU" --release="gcc-4.7.0" --date=2012-03-22 --section=7 gpl.pod > doc/gpl.7.T$$ && \
    mv -f doc/gpl.7.T$$ doc/gpl.7) || \
    (rm -f doc/gpl.7.T$$ && exit 1)
cp doc/gcc.1 doc/g++.1
make[3]: Target 'all' not remade because of errors.
rm gcc.pod
make[3]: Leaving directory '/home/flounder/src/gcc_compile/gcc'
make[2]: *** [Makefile:4101: all-stage1-gcc] Error 2
make[2]: Target 'all-stage1' not remade because of errors.
make[2]: Leaving directory '/home/flounder/src/gcc_compile'
make[1]: *** [Makefile:19342: stage1-bubble] Error 2
make[1]: Target 'stage3-bubble' not remade because of errors.
make[1]: Leaving directory '/home/flounder/src/gcc_compile'
make: *** [Makefile:898: all] Error 2
5
  • Is there any particular need for GCC 4.7.0? GCC 6.2.1 should be backwards compatible with older versions, especially if the class only involves compiling relatively simple programs. Jan 8, 2017 at 6:23
  • I would prefer to use GCC 4.7.0 if possible. The class uses an automated grading system for the programs and compiles our programs using GCC 4.7.0 with the -Werror flag set (among others). I'm not sure if there are any scenario's where GCC 4.7.0 would throw a warning and GCC 6.2.1 would not but that would definitely be one example of why I'd like to use GCC 4.7.0 instead. Also, the class is an operating systems class, so there will be a large amount of threaded and concurrent programming. Jan 8, 2017 at 6:28
  • Be sure to make clean before attempting a rebuild (configure or make), too Jan 8, 2017 at 7:17
  • Yes, I ran the make distclean as suggested in the installation documentation but still came about the errors posted above in the edit Jan 8, 2017 at 7:18
  • I still haven't been able to compile 4.7.0 successfully from 6.2.1, though compiling 5.4.0 has been successful in the build process at time of writing, which may be possible to reverse through the versions to build 4.7.0. Jan 8, 2017 at 9:31

6 Answers 6

8

I agree that using a newer gcc is often not a good option. I had to write a new program for an embedded ARM v4 system running Pengutronix stuck at a 2.6 kernel and an old glibc. Therefore I had to compile the old toolchain on my system.

Often newer GCC versions find errors in the source code, that have been present there for quite some time. Instead of turning the error checking off, I advise to fix the source code instead.

According to the error log the function declaration and the function header do not match for

const char * libc_name_p (const char *, unsigned int);

in file cfns.h included in except.c

Edit cfns.h and change the function declaration

#ifdef __GNUC__
__inline
#endif
const char * libc_name_p (const char *, unsigned int);

to

#ifdef __GNUC__
__inline
#ifdef __GNUC_STDC_INLINE__
__attribute__ ((__gnu_inline__))
#endif
#endif
const char * libc_name_p (const char *, unsigned int);

Then compilation should work.

2
  • 1
    +1 that this answer tackles the problem head on; unlike others that suggest to run away from the it. And it precisely solved the issue. Thanks!
    – codeman48
    Jul 31, 2019 at 16:58
  • This should be the selected answer!
    – Imad
    May 27, 2021 at 16:14
3

You'll probably end up spending an awful lot of time getting GCC 4.7 built on your current system, and in the end you still won't be sure of the result: your school's computers' version of GCC may include distribution patches or even local changes which your version won't have.

I would suggest instead that you run the distribution your school is using in a VM. Your school is using RHEL, and you can too: you can get a no-cost developer subscription from Red Hat Developers; once you've got your subscription, you can download ISOs of any still-supported version of RHEL, so you should be able to install the same version as used on the school computers.

In any case since this is for grading purposes you should always check your code on the school computers before submitting it!

3

To expand on @AxelBe answer: with newer GCC you might need to change in cfns.h both function declaration and definition:

#ifdef __GNUC__
__inline
#endif
const char * libc_name_p (const char *, unsigned int);

or

#ifdef __GNUC__
__inline
#ifdef __GNUC_STDC_INLINE__
__attribute__ ((__gnu_inline__))
#endif
#endif
const char * libc_name_p (const char *, unsigned int);

to

#ifdef __GNUC__
#ifdef __GNUC_STDC_INLINE__
__attribute__ ((__gnu_inline__))
#else
__inline
#endif
#endif
const char * libc_name_p (const char *, unsigned int);

to avoid having __inline and __gnu_inline__ attribute at the same time (resulting in error redeclared inline with 'gnu_inline' attribute). This worked for me when compiling GCC 5.3 with GCC 9.2.

1

Looking at the configure options for GCC, it may successfully make upon issuing ./configure --disable-werror, then building GCC with make -k.

From the man page (make (1)):

 -k, --keep-going
            Continue  as much as possible after an error.  While the 
            target that failed, and those that depend on it, cannot be 
            remade, the other dependencies of these target can be 
            processed all the same.

After doing both of these to compile GCC 4.7.0 under GCC 6.2.1 on x86_64, it seems to compile without issue, however, at time of writing, the compilation has not finished.

2
  • Thank you for the suggestion! But unfortunately, I still ran into some trouble down the line during the initial make -k. I'll add the error output to the question. Jan 8, 2017 at 7:08
  • Yes, I ran the make distclean as suggested in the installation documentation but still came about the errors posted above Jan 8, 2017 at 7:17
0

This is just to "fix" the error. After fixing it, another error shows up.

To fix it -

In file ./gcc/cp/cfns.gperf line 23--26

#ifdef __GNUC__
__inline
#endif
const char * libc_name_p (const char *, unsigned int);

just comment out the ifdef statement.

A new error -

cp/except.o: In function `nothrow_libfn_p':
/home/user/Documents/build/gcc464objdir/gcc/../../gcc-4.6.4/gcc/cp/except.c:932: undefined reference to `libc_name_p'
collect2: error: ld returned 1 exit status
1
  • You have to edit both cfns.gperf and cfns.h .
    – ulatekh
    Apr 27, 2020 at 13:22
0

I am not the resolver, however, after keeping review on the solution. Finally, I can follow the solution on the other thread posted on https://github.com/cbrune/onie/commit/7b7331d45214435a93e604b92c54f05fcdca52b8

Patch the file 132-build_gcc-5_with_gcc-6.patch and the build can continue without a problem.

2
  • Those versions are from the days of the dinosaurs... why doesn't a new(er) version work here?
    – vonbrand
    Feb 19, 2020 at 18:30
  • @vonbrand: CUDA is very specific about which versions of gcc it works with.
    – ulatekh
    Apr 27, 2020 at 13:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .