Page 1 of 1

Cross-compiler build fails when trying to install libgcc

Posted: Mon May 30, 2022 9:09 am
by ThatCodingGuy89
Not sure if this is the right section (not sure what they're called) for this, so tell me if I put this in the wrong section.

Anyways, I was trying to build a cross-compiler (using the instructions from this wiki page: https://wiki.osdev.org/GCC_Cross-Compiler),
and it failed after trying to make the target 'install-target-libgcc'. The full error is:

make[1]: *** No rule to make target 'install'. Stop.
make[1]: Leaving directory '[gcc-source]/i686-elf/libgcc'
Makefile:14104: recipe for target 'install-target-libgcc' failed

I've been trying to automate building the cross-compiler, so I can test the OS by just running 2 scripts. (toolchain.sh and build.sh)
This is probably where something's wrong, as I followed the exact instructions on a different install of Ubuntu before.
I'm not sure where I went wrong though, so here's the full code for toolchain.sh:

Code: Select all

echo "Installing GCC dependencies..."

sudo apt install bison
sudo apt install flex
sudo apt install libgmp3-dev
sudo apt install libmpc-dev
sudo apt install libmpfr-dev
sudo apt install texinfo


echo "Downloading Binutils source..."

mkdir binutils-src

wget -P ./binutils-src/ "https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.gz"


echo "Downloading GCC source..."

mkdir gcc-src

wget -P ./gcc-src/ "https://ftp.gnu.org/gnu/gcc/gcc-12.1.0/gcc-12.1.0.tar.gz"


echo "Extracting the Binutils source..."

cd binutils-src

tar -xvzf binutils-2.38.tar.gz

cd ../


echo "Extracting the GCC source..."

cd gcc-src

tar -xvzf gcc-12.1.0.tar.gz

cd ../


echo "Building the GCC cross-compiler..."

echo "Setting up flags..."
export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"

echo "Building binutils..."
cd binutils-src

mkdir build-binutils
cd build-binutils
../binutils-2.38/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make
make install
cd ../../

echo "Building the GCC cross-compiler..."

cd gcc-src
 
which -- $TARGET-as || echo $TARGET-as is not in the PATH
 
mkdir build-gcc
cd build-gcc
../gcc-12.1.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc

cd ../
And here's a link to the Github repository: https://github.com/ThatCodingGuy86/Unna ... 2/tree/dev

(build instructions are in the `main` branch, you just have to execute `toolchain.sh` before executing `build.sh`, otherwise it will error because the cross-compiler doesn't exist)

Re: Cross-compiler build fails when trying to install libgcc

Posted: Mon May 30, 2022 4:35 pm
by Octocontrabass
ThatCodingGuy89 wrote:The full error is:

make[1]: *** No rule to make target 'install'. Stop.
make[1]: Leaving directory '[gcc-source]/i686-elf/libgcc'
Makefile:14104: recipe for target 'install-target-libgcc' failed
Usually this means there was an error earlier in the process that scrolled away. Do you have the complete log? Can you share it?

Re: Cross-compiler build fails when trying to install libgcc

Posted: Tue May 31, 2022 1:37 am
by Demindiro
I would add

Code: Select all

set -e
at the top of your script(s). This option makes the shell exit immediately on any error so it won't try to run later commands in a potentially broken state.

You may also want to add

Code: Select all

set -x
, which prints each command that is being executed to stderr.

Re: Cross-compiler build fails when trying to install libgcc

Posted: Tue May 31, 2022 2:17 am
by ThatCodingGuy89
Octocontrabass wrote:
ThatCodingGuy89 wrote:The full error is:

make[1]: *** No rule to make target 'install'. Stop.
make[1]: Leaving directory '[gcc-source]/i686-elf/libgcc'
Makefile:14104: recipe for target 'install-target-libgcc' failed
Usually this means there was an error earlier in the process that scrolled away. Do you have the complete log? Can you share it?
For some reason it won't attach the file. Could you tell me how exactly this is supposed to work?

I assumed you can just drag the file over and hit "add file" and then "submit", but nothing happens.

Re: Cross-compiler build fails when trying to install libgcc

Posted: Tue May 31, 2022 2:36 am
by ThatCodingGuy89
Upon doing what Demindiro suggested, my script seems to fail when trying to download a package, seemingly libssl. The full filename that it tried to download is `libssl1.1_1.1.1-1ubuntu2.1~18.04.15_amd64.deb`.

I also noticed a few errors (some major that should have stopped the script) with previous attempts at building:

It seems that binutils failed to build at some point and GCC completely didn't notice this:

Code: Select all

make[4]: *** No rule to make target '../libctf/libctf.la', needed by 'objdump'.  Stop.
make[4]: Leaving directory '/home/testuser/UnnamedOS-V2/binutils-src/build-binutils/binutils'
Makefile:1431: recipe for target 'install-recursive' failed
make[3]: *** [install-recursive] Error 1
make[3]: Leaving directory '/home/testuser/UnnamedOS-V2/binutils-src/build-binutils/binutils'
Makefile:1572: recipe for target 'install' failed
make[2]: *** [install] Error 2
make[2]: Leaving directory '/home/testuser/UnnamedOS-V2/binutils-src/build-binutils/binutils'
Makefile:4103: recipe for target 'install-binutils' failed
make[1]: *** [install-binutils] Error 2
make[1]: Leaving directory '/home/testuser/UnnamedOS-V2/binutils-src/build-binutils'
Makefile:2541: recipe for target 'install' failed
make: *** [install] Error 2
And a few more errors while building GCC:

Code: Select all

i686-elf-as is not in the PATH

checking for isl 0.15 or later... no
required isl version is 0.15 or later

Re: Cross-compiler build fails when trying to install libgcc

Posted: Tue May 31, 2022 8:56 am
by ThatCodingGuy89
Oh. Apparently I'm an idiot. I forgot to update my packages, so it wasn't installing a few dependencies of binutils, and as such, the GCC build failed. It should work now. Should being the operative word.