0

Im trying to compile gcc 4.8.5 under Red Hat 6. This is my procedure:

tar -xvzf archive.tar.gz

cd gcc-4.8.5

./configure --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release \
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object \
--enable-languages=fortran,c --prefix=/opt/gcc4.8.5

make

Then I get the following error:

make  all-am
make[4]: Entering directory `/app/gfortran_build/gcc-4.8.5/host-x86_64-unknown-linux-gnu/lto-plugin'
/bin/sh ./libtool --tag=CC --tag=disable-static  --mode=link gcc -Wall -g  -module -bindir /opt/gcc4.8.5/libexec/gcc/x86_64-unknown-linux-gnu/4.8.5   -o 
liblto_plugin.la -rpath /opt/gcc4.8.5/libexec/gcc/x86_64-unknown-linux-gnu/4.8.5 lto-plugin.lo -Wc,../libiberty/pic/libiberty.a
libtool: link: gcc -shared  .libs/lto-plugin.o    ../libiberty/pic/libiberty.a   -Wl,-soname -Wl,liblto_plugin.so.0 -o .libs/liblto_plugin.so.0.0.0
/usr/bin/ld: ../libiberty/pic/libiberty.a(simple-object-coff.o): relocation R_X86_64_PC32 against undefined symbol `simple_object_set_big_16' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status

I already read about CFLAGS, but I wont get it to work.

kind regards

jww
  • 97,681
  • 90
  • 411
  • 885
pwe
  • 127
  • 1
  • 14
  • 1
    It is 2018. Don't compile an *obsolete* [GCC](http://gcc.gnu.org/) variant. [GCC 4.8](https://gcc.gnu.org/gcc-4.8/) was released in 2013. Compile instead a recent [GCC 7](https://gcc.gnu.org/gcc-7/), released in 2017. Better yet, use the `gcc` available on your distribution – Basile Starynkevitch Jan 05 '18 at 12:57
  • 1
    Also, read about [installing GCC](https://gcc.gnu.org/install/). You cannot build GCC in its source tree, your build tree should be outside of the source tree. Your `--prefix` should rather be some `/opt/gnu`, it is not specific to GCC (and you'll then add `/opt/gnu/bin/` to your `$PATH`) – Basile Starynkevitch Jan 05 '18 at 12:59
  • 1
    Unfortunately, some specific application needs gcc 4.8.5. Im compiling the third version of gcc on this system. I dont understand your second comment: The source is extracted under /app/gfortran_build/ and the prefix path says /opt/gcc4.8.5 – pwe Jan 05 '18 at 13:37
  • No, most applications don't care about the *specific* version of GCC. They care about the [ABI](https://en.wikipedia.org/wiki/Application_binary_interface). It is quite likely that your application could be compiled with a more recent (and not obsolete) version of GCC. You should try to compile with your system's `gcc`; in the unlikely case you do need that GCC version -and I don't think it is the case, unless you need some specific [GCC plugin](https://gcc.gnu.org/onlinedocs/gccint/Plugins.html)-, you should explain (in several paragraphs) why. – Basile Starynkevitch Jan 05 '18 at 13:39
  • ... and the ABI for C programs did not change since many years; for C++ it did change rarely (once every few years). So you should motivate why you need that specific version. At last, building GCC from source code is more a sysadmin task than a developer task; then you'll better ask on [Unix&Linux](https://unix.stackexchange.com/) and give more details – Basile Starynkevitch Jan 05 '18 at 13:44
  • ... and GCC is **documented** to not be buildable in its source tree. If by accident it worked for you once in a while, you can't take that for granted. Again, read the [installation instructions](https://gcc.gnu.org/install/) and the [configuring GCC](https://gcc.gnu.org/install/configure.html) chapter. But I do believe you don't need such an ancient version of GCC. If you take time to compile it from source, use at least a recent version. – Basile Starynkevitch Jan 05 '18 at 13:48
  • I cross posted the question to Unix/Linux. I tried compiling 7.2, but I got the same error. – pwe Jan 05 '18 at 14:04
  • But did you build, as I said, *outside* of the GCC source tree? Then you need to update your question (since the commands are no longer the same) – Basile Starynkevitch Jan 05 '18 at 14:16
  • https://unix.stackexchange.com/q/414990/50557 – Basile Starynkevitch Jan 05 '18 at 14:39
  • BTW, Redhat is expensive, because you buy support. Why don't you use that support? – Basile Starynkevitch Jan 05 '18 at 14:47

2 Answers2

1

GCC is documented to need to be built outside of its source tree; see the configuring chapter of its installation documentation:

First, we highly recommend that GCC be built into a separate directory from the sources which does not reside within the source tree. This is how we generally build GCC; building where srcdir == objdir should still work, but doesn’t get extensive testing; building where objdir is a subdirectory of srcdir is unsupported.

So you need to build it according to that rule. Hence your GCC build:

cd gcc-4.8.5
#wrong code from the original question! Don't use that
./configure --enable-bootstrap --enable-shared \
      --enable-threads=posix --enable-checking=release \
      --with-system-zlib --enable-__cxa_atexit \
      --disable-libunwind-exceptions --enable-gnu-unique-object \
      --enable-languages=fortran,c --prefix=/opt/gcc4.8.5

is wrong; I would recommend at least:

  cd gcc-4.8.5
  mkdir ../_BuildGCC
  cd ../_BuildGCC
  ../gcc-4.8.5/configure --enable-bootstrap --enable-shared \
      --enable-threads=posix --enable-checking=release \
      --with-system-zlib --enable-__cxa_atexit \
      --disable-libunwind-exceptions --enable-gnu-unique-object \
      --enable-languages=fortran,c --prefix=/opt/gnu \
      --program-suffix=-mine

then, after the entire build, probably with

 make -j4

followed by some mkdir /opt/gnu with appropriate user and permission, then (in the same _BuildGCC)

make install DESTDIR=/tmp/gccinst

and finally cp -vr /tmp/gccinst/opt/gnu /opt/gnu to be run appropriately (perhaps as root...., and perhaps cp -va)

Then you would add /opt/gnu/bin/ to your PATH variable, and you would use gcc-mine to compile your code.

BTW, GCC is compatible for C programs since the ABI don't change. And GCC 4.8 is obsolete and unsupported. You'll better compile from source the supported versions (listed on gcc.gnu.org; in January 2018, GCC 7.2 & GCC 6.4)

Perhaps your particular Redhat system requires additional/specific CFLAGS to be appended into your configure command. You could ask your Redhat support, or try to append CFLAGS=-fPIE or CFLAGS=-fPIC at the end of your ../gcc-4.8.5/configure command.

At last, you might perhaps get such help on gcc-help@gcc.gnu.org, but you'll better try with a recent GCC. Few GCC folks remember 4.8 ....

If you really need precisely GCC 4.8 (but I doubt that), you could buy costly support (e.g. from RedHat or AdaCore folks) if needed.

With Google I found Installing gcc 4.8 and Linuxbrew on CentOS 6

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • Did you try with GCC 7? IIRC, the autoconf machinery has been improved thru the years. – Basile Starynkevitch Jan 05 '18 at 14:49
  • 1
    Available gcc packages, RHEL6 : gcc53-c++-5.3.0-1.el6.x86_64.rpm, gcc49-c++-4.9.3-1.el6.x86_64.rpm ... + the **devtoolset** packages. See https://stackoverflow.com/questions/47175706/how-to-install-gcc-4-9-2-on-rhel-7-4/47189915#47189915 – Knud Larsen Jan 05 '18 at 18:54
1

it worked with the following:

../gcc-4.8.5/configure CC="/opt/gcc4.5/bin/gcc" --prefix=/opt/gcc4.8.5 --enable-languages=c,c++,fortran --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object

The interesting part is CC=...

The installed gcc-version is 4.4. With this version, the compiling fails.

kind regards

pwe
  • 127
  • 1
  • 14