30

I'm actually reading the LFS book (version 7.1) and I'm blocked at page 53. Trying to compile gcc, I tried the following command:

./configure --target=$LFS_TGT --prefix=$LFS/build/gcc-build --disable-nls\
--disable-shared --disable-multilib --disable-decimal-float --disable-threads\
--disable-libmudflap --disable-libssp --disable-libgomp --disable-libquadmath\
--disable-target-libiberty --disable-target-zlib\
--enable-languages=c\
--without-ppl --without-cloog\
--with-mpfr-include=$LFS/source/mpfr/src
--with-mpfr-lib=$LFS/source/mpfr/src/.libs\
--with-gmp-include=/mnt/LFS/source/gmp\
--with-gmp-lib=/mnt/LFS/source/gmp/.libs\
--with-mpc-include=/mnt/LFS/source/mpc/src\
--with-mpc-lib=/mnt/LFS/source/mpc/src/.libs

to run the configure script of gcc (of course I already compiled mpfr, mpc and gmp as well). But once I launch:

make -j4

I get the following error:

checking for suffix of object files... configure: error: in `/mnt/LFS/source/gcc-4.6.2/x86_64-lfs-linux-gnu/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details.
make[1]: *** [configure-target-libgcc] Error 1

I tried to google for it and tried the solutions I found but nothing worked. Does anyone know why I get this error?

Shahbaz
  • 46,337
  • 19
  • 116
  • 182
E-Kami
  • 2,529
  • 5
  • 30
  • 50
  • Happens when configure tries to compile some test programs. [This link](http://gcc.gnu.org/wiki/FAQ#configure_suffix) might be useful. – ArjunShankar Jul 16 '12 at 10:10
  • 3
    *See `config.log' for more details.* -- Good advice, that's why it is in the error message. – DevSolar Jul 16 '12 at 12:26
  • Thanks for the link. But I tried everything, and I didn't got any clue on what the problem can come from. Some forums says that it is a bug of GCC which doesn't read libs of mpc or mpfr. I'll try to investigate again. Thanks anyway – E-Kami Jul 19 '12 at 21:53

6 Answers6

25

This issue is caused by dyanmic link library path issue when the test programs try to link against libmpc/libmpfr/libgmp.

Append below environment variable to allow ld link against the correct so file:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/mpc/lib/

Then try build gcc again.

Fei
  • 1,450
  • 1
  • 17
  • 30
  • 4
    Can you give an example to such a path `/path/to/mpc/lib/` or how do I find it? – WebQube Aug 08 '14 at 09:59
  • @WebQube Can you not execute `sudo find / -iname "libmpc.so"`? That will let you know the path or run the command `whereis libmpc.so` or `locate libmpc.so`. – enthusiasticgeek Oct 21 '14 at 09:13
  • There're implications though - as I know mpc library is not installed by default on *nix systems and you may need to install it manually - the actual path depends on what you pass to `configure --prefix=/xx/xx`, by default configure script would install to `/user/local/lib/` – Fei Nov 18 '15 at 04:59
  • 7
    for a cross compiler should this be the path to the library on the build machine, the host machine, or the target machine? – Rick Jun 10 '21 at 21:30
19

"Building GCC is not trivial, but is not difficult if you follow the instructions carefully. Many people rush into trying to build it without reading the installation docs properly and make one or more of these common mistakes:

  1. do not run ./configure from gcc src dir (this is not supported) => you need to run configure from outside the gcc source directory

  2. Note: if GCC links dynamically to the prerequisite libs (GMP/MPFR/MPC) then the shared libraries must be in the dynamic linker's path (LD_LIBRARY_PATH), both when building gcc and when using the installed compiler."

Simple example (without dynamic link to GMP/MPFR/MPC):

tar xzf gcc-4.8.0.tar.gz
cd gcc-4.8.0
./contrib/download_prerequisites
cd ..
mkdir objdir
cd objdir
$PWD/../gcc-4.8.0/configure --prefix=/opt/gcc-4.8.0 
make
make install

Sources: Advogato Doc - GNU Doc

Axel Borja
  • 3,718
  • 7
  • 36
  • 50
  • 2
    Up vote for building without dynamic link, it really makes life easy. – TwilightSun Mar 16 '15 at 06:53
  • What did you do exaclty? There are 2 different solutions in the answer :) – Axel Borja Oct 08 '19 at 14:57
  • Now I can build dropped gcc 4.3 on OpenBSD 7.2 (arm, aarch64): `MAKEINFO=missing $PWD/../gcc-4.3.4/configure --disable-Werror --with-libsodium --prefix=/usr/local --sysconfdir=/etc mandir=/usr/local/man --infodir=/usr/local/info --localstatedir=/var --disable-silent-rules --with-mpfr=/usr/local --disable-libmudflap --disable-libgomp --disable-libgmp --enable-languages=c --target=arm-none-eabi --build=arm-none-eabi; gmake LIBTOOL=/usr/bin/libtool` – user1742529 Feb 22 '23 at 12:42
  • Instead of egcc you can use clang `export CC="cc -std=gnu99 -fgnu89-inline"` and `export CXX=clang++` – user1742529 Feb 22 '23 at 13:32
6

This error message can arise from a number of different reasons. The best way to figure out which one is to check the logfile '/home/manu/gcc/gcc/i686-pc-linux-gnu/libgcc/config.log' in the example below. Or in the original posters case '/mnt/LFS/source/gcc-4.6.2/x86_64-lfs-linux-gnu/libgcc' and look for the last error line.

Quoting GCC FAQ: http://gcc.gnu.org/wiki/FAQ#configure_suffix

Like any of the GNU projects, GCC is using the GNU autotools to commonly configure the compilation for the specifics of the build system. The configure script thereby uses small test programs - usually called conftest.c - to test if certain functions and/or features are available. If the compilation of such a test program fails, you'll see an error message like:

 checking for suffix of object files... configure: error: in
 `/home/manu/gcc/gcc/i686-pc-linux-gnu/libgcc': configure: error:
 cannot compute suffix of object files: cannot compile See `config.log'
 for more details. make[2]: *** [configure-stage1-target-libgcc] Error
 1 make[2]: Leaving directory `/home/manu/gcc/gcc'

This error message is quite misleading and frequently the problem has nothing to do with the message. You have to check the file 'config.log' in the directory where the error occurred. In the example above, you would have to check the 'config.log' file in the directory '/home/manu/gcc/gcc/i686-pc-linux-gnu/libgcc'. There might be several test programs that failed during the configuration, but some of these failures are non-critical. Check for the last error entry in the file.

Common causes for this error message are:

  • Required libraries for the GCC build are missing, specifically MPFR, GMP and MPC. If installed as shared libraries they must be in the runtime linker's search path so they can be found. Please, follow the instructions in the answer to Why does my ./configure and make fail?

  • The compiler crashed. For example, if there is an error such as 'conftest.c: internal compiler error:', this indicates a bug in the compiler. If you are using an unmodified version of GCC, please follow the procedure to report the bug.

Stian Svedenborg
  • 1,797
  • 11
  • 27
2

This happens while creating a cross-compiler.

It's not referring to the top-level config.log, but $LFS_TGT/libgcc/config.log.

For me, in there, it says:

configure:3566: /foo/gcc/build/./gcc/xgcc -B/foo/gcc/build/./gcc/ -B/opt/gcc-cross-11.1.0/aarch64-none-elf/bin/ -B/opt/gcc-cross-11.1.0/aarch64-none-elf/lib/ -isystem /opt/gcc-cross-11.1.0/aarch64-none-elf/include -isystem /opt/gcc-cross-11.1.0/aarch64-none-elf/sys-include    -o conftest -g -O2   conftest.c  >&5
conftest.c:9:10: fatal error: stdio.h: No such file or directory
    9 | #include <stdio.h>
      |          ^~~~~~~~~
compilation terminated.
configure:3569: $? = 1
configure:3782: checking for suffix of object files
configure:3804: /foo/gcc/build/./gcc/xgcc -B/foo/gcc/build/./gcc/ -B/opt/gcc-cross-11.1.0/aarch64-none-elf/bin/ -B/opt/gcc-cross-11.1.0/aarch64-none-elf/lib/ -isystem /opt/gcc-cross-11.1.0/aarch64-none-elf/include -isystem /opt/gcc-cross-11.1.0/aarch64-none-elf/sys-include    -c -g -O2  conftest.c >&5
/foo/gcc/build/./gcc/as: line 106: exec: -E: invalid option
exec: usage: exec [-cl] [-a name] [command [arguments ...]] [redirection ...]
configure:3808: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "GNU C Runtime Library"
| #define PACKAGE_TARNAME "libgcc"
| #define PACKAGE_VERSION "1.0"
| #define PACKAGE_STRING "GNU C Runtime Library 1.0"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL "http://www.gnu.org/software/libgcc/"
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:3822: error: in `/foo/gcc/build/aarch64-none-elf/libgcc':
configure:3824: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details

Was your logfile similar?

It's my belief that the gcc compilation/installation process will take the various includes, run them through fixincludes to fix problems and tailor them to the target arch. The expected file is not present.

Referring to the Prerequisites page, I believe this section is relevant (emphasis mine):

C standard library and headers

In order to build GCC, the C standard library and headers must be present for all
target variants for which target libraries will be built (and not only the variant
of the host C++ compiler).

This affects the popular ‘x86_64-pc-linux-gnu’ platform (among other multilib
targets), for which 64-bit (‘x86_64’) and 32-bit (‘i386’) libc headers are usually
packaged separately. If you do a build of a native compiler on ‘x86_64-pc-linux-gnu’,
make sure you either have the 32-bit libc developer package properly installed (the
exact name of the package depends on your distro) or you must build GCC as a 64-bit
only compiler by configuring with the option --disable-multilib. Otherwise, you may
encounter an error such as ‘fatal error: gnu/stubs-32.h: No such file’

I believe that the solution is to obtain headers for the TARGET platform.

Lance E.T. Compte
  • 932
  • 1
  • 11
  • 33
1

The problem is the assembler, "as" is missing. Build and install binutils for the target first.

Tim Chick
  • 11
  • 1
1

In my case it was:

export LD_LIBRARY_PATH=/usr/mpc-082/lib:/usr/gmp501/lib:/usr/libelf0812/lib

Whereas each of the above library is the destination of what additional libraries you installed appended with /lib at the end.

Example: Lib-MPC:
1) Downloaded onto /usr/src/libmpc-src
2) cd into /usr/src/mpc-082
3) ../configure --prefix=/usr/mpc-082
4) make
5) make install 
6) once installed, verify that you have the new libs installed under /usr/mpc-082-lib
7) add it to your LD_LIBRARY_PATH by doing:
export LD_LIBRARY_PATH=/usr/mpc-082/lib:$LD_LIBDADY_PATH
8) Repeat the same with your LibELF, and LibGMP
9) Go back and compile your GCC, should work after this.

Cheers

H

Heider Sati
  • 2,476
  • 26
  • 28