Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gcc compilation "cannot compute suffix of object files: cannot compile"

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?

like image 973
E-Kami Avatar asked Jul 16 '12 09:07

E-Kami


4 Answers

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.

like image 177
Fei Avatar answered Oct 18 '22 15:10

Fei


"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

like image 34
Axel Borja Avatar answered Oct 18 '22 14:10

Axel Borja


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.

like image 41
Stian Svedenborg Avatar answered Oct 18 '22 15:10

Stian Svedenborg


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.

like image 2
Lance E.T. Compte Avatar answered Oct 18 '22 14:10

Lance E.T. Compte