C语言 构建 GCC make: *** [all] 错误 2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33450401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 12:11:40  来源:igfitidea点击:

Building GCC make: *** [all] Error 2

cubuntugccmakefileg++

提问by

I am trying to set up a cross-compiler for i686-elf on Ubuntufollowing the OSDev GCC Cross-Compiler Tutuorial.However, the code to set up GCC fails to build every time. I know my sources are not out of date because I sudo apt-get update'd before doing anything.

我正在尝试按照OSDev GCC 交叉编译器教程在 Ubuntu 上为 i686-elf 设置交叉编译器。但是,设置 GCC 的代码每次都无法构建。我知道我的资料来源并没有过时,因为我sudo apt-get update在做任何事情之前都会这样做。

In order to get the packages I needed, I did:

为了获得我需要的包,我做了:

sudo apt-get install g++
sudo apt-get install make
sudo apt-get install bison
sudo apt-get install flex
sudo apt-get install libgmp3-dev
sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg
sudo apt-get install mpc
sudo apt-get install texinfo
sudo apt-get install libcloog-isl-dev

I think there is no problem with that method?

我觉得那个方法没有问题?

Then, with gcc-5.2.0and binutils-2.25.1(in ubuntu, bintuils appears to not work with anything above that old version) I installed binutils just fine. I went to build gcc but when I typed in make, I got the following error:

然后,使用gcc-5.2.0binutils-2.25.1(在 ubuntu 中,bintuils 似乎不适用于旧版本之上的任何东西)我安装 binutils 就好了。我去构建gcc,但是当我输入make时,出现以下错误:

Unfortunately, I can't copy+paste 30 pages in, but this all the code near the end:

不幸的是,我无法复制+粘贴 30 页,但这是接近尾声的所有代码:

checking command to parse nm output from gcc  -m32 object... failed
checking how to run the C preprocessor... /lib/cpp
checking for ANSI C header files... no
checking for sys/types.h... no
checking for sys/stat.h... no
checking for stdlib.h... no
checking for string.h... no
checking for memory.h... no
checking for strings.h... no
checking for inttypes.h... no
checking for stdint.h... no
checking for unistd.h... no
checking for dlfcn.h... no
checking for objdir... .libs
checking if gcc  -m32 supports -fno-rtti -fno-exceptions... no
checking for gcc  -m32 option to produce PIC... -fPIC -DPIC
checking if gcc  -m32 PIC flag -fPIC -DPIC works... yes
checking if gcc  -m32 static flag -static works... no
checking if gcc  -m32 supports -c -o file.o... yes
checking if gcc  -m32 supports -c -o file.o... (cached) yes
checking whether the gcc  -m32 linker (ld -m elf_x86_64 -m elf_i386) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
Makefile:9590: recipe for target 'configure-zlib' failed
make[1]: *** [configure-zlib] Error 1
make[1]: Leaving directory '/home/david/scr'
Makefile:876: recipe for target 'all' failed
make: *** [all] Error 2

And this is the part (right after that) where something really bad happens:

这是发生非常糟糕的事情的部分(紧随其后):

checking dynamic linker characteristics... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.
Makefile:9590: recipe for target 'configure-zlib' failed
make[1]: *** [configure-zlib] Error 1
make[1]: Leaving directory '/home/david/scr'
Makefile:876: recipe for target 'all' failed
make: *** [all] Error 2

Can anyone tell me what I am doing wrong and how I would fix it?

谁能告诉我我做错了什么以及我将如何解决它?

Thanks!

谢谢!

采纳答案by

The problem was that I wasn't installing mpc from source.

问题是我没有从源代码安装 mpc。

Here is the finished file (setup-gcc.sh):

这是完成的文件(setup-gcc.sh):

####################################
echo Stage 1 - Building Dependencies
####################################

# make a working directory
cd $HOME/Documents
rm -rf Cross
mkdir Cross
cd Cross

# install or update all apt-get dependencies
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install gcc -y                 # not cross
sudo apt-get install g++ -y
sudo apt-get install make -y
sudo apt-get install bison -y
sudo apt-get install flex -y
sudo apt-get install gawk -y
sudo apt-get install libgmp3-dev -y
sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg -y
sudo apt-get install mpc -y
sudo apt-get install texinfo -y            # optional
sudo apt-get install libcloog-isl-dev -y   # optional
sudo apt-get install build-essential -y
sudo apt-get install glibc-devel -y
sudo apt-get -y install gcc-multilib libc6-i386 -y

# download and unpack necessary files
wget http://ftpmirror.gnu.org/binutils/binutils-2.25.1.tar.gz
wget http://ftpmirror.gnu.org/gcc/gcc-5.3.0/gcc-5.3.0.tar.gz
wget http://ftpmirror.gnu.org/mpc/mpc-1.0.3.tar.gz
for f in *.tar*; do tar zvxf $f; done

# create installation directory
mkdir Install
export PREFIX="$HOME/Documents/Cross/Install"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"

################################
echo Stage 2 - Building Compiler
################################

# install mpc
mkdir build-mpc
cd build-mpc
../mpc-1.0.3/configure --prefix="$PREFIX"
make -j2
make -j2 check
make -j2 install
cd ..

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

# install gcc
mkdir build-gcc
cd build-gcc
../gcc-5.3.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers --with-mpc="$PREFIX"
make -j2 all-gcc
make -j2 all-target-libgcc
make -j2 install-gcc
make -j2 install-target-libgcc

Once you have it installed, you can run it with:

安装后,您可以使用以下命令运行它:

export PREFIX="$HOME/Documents/Cross/Install"
export TARGET=i686-elf
$PREFIX/bin/$TARGET-gcc --version

Unfortunately, doing this inside of an alias or bash script doesn't seem to properly launch it, so, unless this gets fixed, you might have to just store the script in a text file and copy-paste it into terminal every time you reboot.

不幸的是,在别名或 bash 脚本中执行此操作似乎无法正确启动它,因此,除非此问题得到修复,否则您可能只需将脚本存储在文本文件中,并在每次重新启动时将其复制粘贴到终端中.

To uninstall your cross-compiler, simply delete the $HOME/Documents/Cross directory.

要卸载您的交叉编译器,只需删除 $HOME/Documents/Cross directory.

As a final note, changing the installation directory or target is as easy as changing the value of $PREFIXor $TARGET, but I wouldn't recommend it, because you may run into other unexpected problems.

最后要注意的是,更改安装目录或目标与更改$PREFIX或的值一样简单$TARGET,但我不建议这样做,因为您可能会遇到其他意外问题。

回答by Yazhss

In addition to --with-system-zlib, it worked for me when I use --disable-multiliboption.

此外--with-system-zlib,当我使用--disable-multilib选项时,它对我有用。