Error when compiling libgcc

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
catOS
Member
Member
Posts: 28
Joined: Tue Mar 31, 2020 6:28 pm

Error when compiling libgcc

Post by catOS »

I'm getting this error:

Code: Select all

checking for suffix of object files... configure: error: in `/home/ack/ackos/toolchain/gcc/gcc-10.2.0/x86_64-elf/libgcc':
configure: error: cannot compute suffix of object files: cannot compile
See `config.log' for more details
make: *** [Makefile:12629: configure-target-libgcc] Error 1
My cross compiler compiling script:

Code: Select all

#!/bin/bash
set -e

COMPILER_TARGET=x86_64-elf
COMPILER_PREFIX="local"
# COMPILER_SYSROOT="../sysroot"

BINUTILS_VERSION=2.35
BINUTILS_WGET_LOC=binutils.tar.gz
BINUTILS_DIR=binutils

GCC_VERSION=10.2.0
GCC_WGET_LOC=gcc.tar.gz
GCC_DIR=gcc

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/libmpc.so:/usr/lib/x86_64-linux-gnu/libmpfr.so:/usr/lib/x86_64-linux-gnu/libgmp.so

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

cd $DIR

if [ ! -e $BINUTILS_WGET_LOC ]; then
	echo Downloading binutils
	wget -O $BINUTILS_WGET_LOC "https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.gz"
else
	echo "$BINUTILS_WGET_LOC already exists, skipping download"
fi

if [ ! -e $GCC_WGET_LOC ]; then
	echo Downloading GCC
	wget -O $GCC_WGET_LOC "https://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-$GCC_VERSION.tar.gz"
else
	echo "$GCC_WGET_LOC already exists, skipping download"
fi

if [ ! -e $BINUTILS_DIR ]; then
	echo Extracting binutils
	mkdir "$BINUTILS_DIR"
	tar -xf binutils.tar.gz -C "$BINUTILS_DIR"
else
	echo "binutils has already been extracted, skipping"
fi

if [ ! -e $GCC_DIR ]; then
	echo Extracting GCC
	mkdir "$GCC_DIR"
	tar xvzf gcc.tar.gz -C "$GCC_DIR"
else
	echo "GCC has already been extracted, skipping"
fi

mkdir -p $COMPILER_PREFIX

if [ -z "$MAKEJOBS" ]; then
    MAKEJOBS=$(nproc)
fi

if [ ! -d "build" ]; then
	mkdir build
fi

if [ ! -d "build/binutils" ]; then
	echo "Compiling binutils"
	mkdir -p "build/binutils"
	pushd $BINUTILS_DIR/binutils-$BINUTILS_VERSION
		echo "Configuring binutils"
		"$DIR/$BINUTILS_DIR/binutils-$BINUTILS_VERSION/configure" \
			--target=$DIR/$COMPILER_TARGET \
			--prefix="$DIR/$COMPILER_PREFIX" \
			--disable-werror \
			--disable-nls \
			--with-sysroot || exit 1
			# --with-sysroot="$DIR/$COMPILER_SYSROOT" \

		echo "Running make on binutils"
		make
		echo "Running make install on binutils"
		make install
	popd
else
	echo "build/binutils already exists, skipping";
fi

if [ ! -d "build/gcc" ]; then
	echo "Compiling GCC"
	mkdir -p "build/gcc"
	pushd $GCC_DIR/gcc-$GCC_VERSION
		echo "Configuring GCC"
		# You must provide the full path when using the configure script
		"$DIR/$GCC_DIR/gcc-$GCC_VERSION/configure" \
				--target=$COMPILER_TARGET \
				--prefix="$DIR/$COMPILER_PREFIX" \
				--disable-nls \
				--without-headers \
				--enable-languages=c,c++ \
				--with-gmp=/usr --with-mpc=/opt/local --with-mpfr=/opt/local
		# make -C "$DIR/../" install-headers || exit 1

		echo "Running make all-gcc on GCC"
		make -j $MAKEJOBS all-gcc

		echo "Running make all-target-libgcc on GCC"
		make -j $MAKEJOBS all-target-libgcc

		echo "Running make install-gcc on GCC"
		make install-gcc
		echo "Running make install-target-libgcc on GCC"
		make install-target-libgcc

		echo "Compiling libstdc++"
		make all-target-libstdc++-v3
		echo "Installing libstdc++"
		make install-target-libstdc++-v3
	popd
    else
        echo "build/gcc already exists, skipping";
    fi

Visit ackOS's GitHub page:
>> https://github.com/ackOS-project/ackOS <<
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: Error when compiling libgcc

Post by Octocontrabass »

catOS wrote:

Code: Select all

See `config.log' for more details
So, what does config.log say?
User avatar
catOS
Member
Member
Posts: 28
Joined: Tue Mar 31, 2020 6:28 pm

Re: Error when compiling libgcc

Post by catOS »

Octocontrabass wrote:
catOS wrote:

Code: Select all

See `config.log' for more details
So, what does config.log say?

Code: Select all

/home/ack/ackos/toolchain/gcc/gcc-10.2.0/host-x86_64-pc-linux-gnu/gcc/as: 106: exec: -o: not found
configure:3804: $? = 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:3818: error: in `/home/ack/ackos/toolchain/gcc/gcc-10.2.0/x86_64-elf/libgcc':
configure:3820: error: cannot compute suffix of object files: cannot compile
Visit ackOS's GitHub page:
>> https://github.com/ackOS-project/ackOS <<
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: Error when compiling libgcc

Post by Octocontrabass »

Google says that error means your cross-binutils is not installed correctly. And looking at your script, I see one possible reason why.
catOS wrote:

Code: Select all

			--target=$DIR/$COMPILER_TARGET \
There should be no directories in your target triplet.
User avatar
catOS
Member
Member
Posts: 28
Joined: Tue Mar 31, 2020 6:28 pm

Re: Error when compiling libgcc

Post by catOS »

Octocontrabass wrote:Google says that error means your cross-binutils is not installed correctly. And looking at your script, I see one possible reason why.
catOS wrote:

Code: Select all

			--target=$DIR/$COMPILER_TARGET \
There should be no directories in your target triplet.
Now I get this error

Code: Select all

make[1]: Entering directory '/home/ack/Documents/hello-world/asm/os/toolchain/gcc/gcc-10.2.0/x86_64-elf/libgcc'
Makefile:183: ../.././gcc/libgcc.mvars: No such file or directory
make[1]: *** No rule to make target '../.././gcc/libgcc.mvars'. Stop.
make[1]: Leaving directory '/home/ack/Documents/hello-world/asm/os/toolchain/gcc/gcc-10.2.0/x86_64-elf/libgcc'
make: *** [Makefile:12701: all-target-libgcc] Error 
Visit ackOS's GitHub page:
>> https://github.com/ackOS-project/ackOS <<
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: Error when compiling libgcc

Post by Octocontrabass »

Google says that error means you're trying to build GCC in the same directory where you unpacked the GCC source. You need to run the configure script in a separate directory.
Post Reply