安装gcc时使用make时编译错误

问题描述 投票:0回答:1

我已经把

.tar.bz2
(我正在安装gcc-4.2.2)文件放到一个文件夹中,进入这个文件夹,并使用它的
./configure
,在命令行上写下
make
。正是在
make
之后,我遇到了很多编译错误。最后,我得到了这样的信息:

make[3]: *** [Makefile:2181: toplev.o] Error 1

make[3]: Leaving directory '/home/kali/Downloads/gcc-4.2.2/host-x86_64-unknown-linux-gnu/gcc'

make[2]: *** [Makefile:4519: all-stage1-gcc] Error 2

make[2]: Leaving directory '/home/kali/Downloads/gcc-4.2.2'

make[1]: *** [Makefile:15591: stage1-bubble] Error 2

make[1]: Leaving directory '/home/kali/Downloads/gcc-4.2.2'

make: *** [Makefile:651: all] Error 2

我应该怎样做才能成功安装gcc并且没有错误?

c gcc gnu-make
1个回答
0
投票

您的第一组错误以

make[3]: *** [Makefile:2181: toplev.o] Error 1
开头——这很遗憾,因为有用的信息出现在该行输出之前。除了几乎不可读之外,该图像不包含错误消息 - 它包含可以(必要地,必须)忽略的各种警告。

当我尝试在 RHEL 7 上构建 GCC 4.2.2 时(根据

/etc/Redhat-release
,“Red Hat Enterprise Linux Server 版本 7.4 (Maipo)”),使用我编译的 GCC 13.2.0 编译器,并且在没有并行的情况下运行构建使消息可读且不交错),我得到:

gcc   -g -fkeep-inline-functions -DIN_GCC   -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Wold-style-definition -Wmissing-format-attribute -fno-common   -DHAVE_CONFIG_H -I. -I. -I../../gcc-4.2.2/gcc -I../../gcc-4.2.2/gcc/. -I../../gcc-4.2.2/gcc/../include -I../../gcc-4.2.2/gcc/../libcpp/include  -I../../gcc-4.2.2/gcc/../libdecnumber -I../libdecnumber    \
  -DTARGET_NAME=\"x86_64-unknown-linux-gnu\" \
  -c ../../gcc-4.2.2/gcc/toplev.c -o toplev.o
In file included from ../../gcc-4.2.2/gcc/toplev.c:30:
../../gcc-4.2.2/gcc/basic-block.h: In function ‘single_succ_edge’:
../../gcc-4.2.2/gcc/system.h:576:55: warning: ISO C does not support ‘__FUNCTION__’ predefined identifier [-Wpedantic]
  576 |    ((void)(!(EXPR) ? fancy_abort (__FILE__, __LINE__, __FUNCTION__), 0 : 0))
      |                                                       ^~~~~~~~~~~~
../../gcc-4.2.2/gcc/basic-block.h:622:3: note: in expansion of macro ‘gcc_assert’
  622 |   gcc_assert (single_succ_p (bb));
      |   ^~~~~~~~~~
…
… 74 lines omitted
…
../../gcc-4.2.2/gcc/toplev.c: At top level: 
../../gcc-4.2.2/gcc/toplev.c:539:1: error: redefinition of ‘floor_log2’
  539 | floor_log2 (unsigned HOST_WIDE_INT x)
      | ^~~~~~~~~~
In file included from ../../gcc-4.2.2/gcc/toplev.c:58:
../../gcc-4.2.2/gcc/toplev.h:173:1: note: previous definition of ‘floor_log2’ with type ‘int(long unsigned int)’
  173 | floor_log2 (unsigned HOST_WIDE_INT x)
      | ^~~~~~~~~~
../../gcc-4.2.2/gcc/toplev.c:574:1: error: redefinition of ‘exact_log2’
  574 | exact_log2 (unsigned HOST_WIDE_INT x)
      | ^~~~~~~~~~
../../gcc-4.2.2/gcc/toplev.h:179:1: note: previous definition of ‘exact_log2’ with type ‘int(long unsigned int)’
  179 | exact_log2 (unsigned HOST_WIDE_INT x)
      | ^~~~~~~~~~
…
… 77 lines omitted
…
../../gcc-4.2.2/gcc/toplev.c:1814:65: warning: unquoted option name ‘-Os’ in format [-Wformat-diag]
 1814 |       warning (0, "-fprefetch-loop-arrays is not supported with -Os");
      |                                                                 ^~~
../../gcc-4.2.2/gcc/toplev.c:1837:20: warning: unquoted option name ‘-fstack-protector’ in format [-Wformat-diag]
 1837 |       warning (0, "-fstack-protector not supported for this target");
      |                    ^~~~~~~~~~~~~~~~~
make[3]: *** [Makefile:2181: toplev.o] Error 1
make[3]: Leaving directory '/work1/jleffler/tmp/gcc-4.2.2-obj/gcc'
make[2]: *** [Makefile:4520: all-stage1-gcc] Error 2
make[2]: Leaving directory '/work1/jleffler/tmp/gcc-4.2.2-obj'
make[1]: *** [Makefile:15592: stage1-bubble] Error 2
make[1]: Leaving directory '/work1/jleffler/tmp/gcc-4.2.2-obj'
make: *** [Makefile:15876: bootstrap] Error 2

好消息是,最后的 make 消息与您所看到的非常匹配(

all-stage1-gcc
stage1-bubble
的行号相差一)。这意味着我可能遇到了与您相同的问题。

另一个好消息是 GCC 13.2.0 告诉我们去哪里寻找:

toplev.c

 538 int
 539 floor_log2 (unsigned HOST_WIDE_INT x)
 540 {
…
 573 int
 574 exact_log2 (unsigned HOST_WIDE_INT x)
 575 {

toplev.h

172 extern inline int
173 floor_log2 (unsigned HOST_WIDE_INT x)
174 {
…
178 extern inline int
179 exact_log2 (unsigned HOST_WIDE_INT x)
180 {

呃!内联函数语义是 GCC 多年来发生变化的领域之一。 GCC 的Changes文档提到了内联函数处理方式即将发生的变化。

我们可以尝试通过多种方法来解决这个问题。我认为最可靠的方法是放弃内联函数定义。这是我创建的上下文差异(补丁文件):

--- toplev-20070901.092830.h    2007-09-01 09:28:30.000000000 -0600
+++ toplev.h    2023-12-06 22:13:45.229614401 -0700
@@ -169,6 +169,7 @@
 #  define CTZ_HWI __builtin_ctz
 # endif
 
+#ifdef DO_IT_THE_OFFICIAL_WAY
 extern inline int
 floor_log2 (unsigned HOST_WIDE_INT x)
 {
@@ -180,6 +181,11 @@
 {
   return x == (x & -x) && x ? (int) CTZ_HWI (x) : -1;
 }
+#else
+extern int floor_log2 (unsigned HOST_WIDE_INT x);
+extern int exact_log2 (unsigned HOST_WIDE_INT x);
+#endif /* DO_IT_THE_OFFICIAL_WAY */
+
 #endif /* GCC_VERSION >= 3004 */
 
 /* Functions used to get and set GCC's notion of in what directory

就这样,编译工作继续进行,并走得更远。还是很吵。我显示的错误接近构建日志文件中的第 113,000 行。

让编译运行一段时间后,一旦代码开始编译自己的源代码,警告就会大大减少。然而,您还没有完全摆脱困境 - GCC 4.2.2 中的错误消息远不如 GCC 13.2.0 中的错误消息那么全面 - 这是 GCC 团队在改进方面做得非常出色的领域之一产品。

rm -f 32/libgcov.a
ar  rc 32/libgcov.a libgcc/32/_gcov.o libgcc/32/_gcov_merge_add.o libgcc/32/_gcov_merge_single.o libgcc/32/_gcov_merge_delta.o libgcc/32/_gcov_fork.o libgcc/32/_gcov_execl.o libgcc/32/_gcov_execlp.o libgcc/32/_gcov_execle.o libgcc/32/_gcov_execv.o libgcc/32/_gcov_execvp.o libgcc/32/_gcov_execve.o libgcc/32/_gcov_interval_profiler.o libgcc/32/_gcov_pow2_profiler.o libgcc/32/_gcov_one_value_profiler.o
ranlib 32/libgcov.a
/work1/jleffler/tmp/gcc-4.2.2-obj/./gcc/xgcc -B/work1/jleffler/tmp/gcc-4.2.2-obj/./gcc/ -B/opt/gcc/v4.2.2/x86_64-unknown-linux-gnu/bin/ -B/opt/gcc/v4.2.2/x86_64-unknown-linux-gnu/lib/ -isystem /opt/gcc/v4.2.2/x86_64-unknown-linux-gnu/include -isystem /opt/gcc/v4.2.2/x86_64-unknown-linux-gnu/sys-include -O2  -O2 -g -O2  -DIN_GCC    -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED  -I. -I. -I../../gcc-4.2.2/gcc -I../../gcc-4.2.2/gcc/. -I../../gcc-4.2.2/gcc/../include -I../../gcc-4.2.2/gcc/../libcpp/include  -I../../gcc-4.2.2/gcc/../libdecnumber -I../libdecnumber -m32 -fexceptions -fvisibility=hidden -DHIDE_EXPORTS -c ../../gcc-4.2.2/gcc/unwind-dw2.c -o libgcc/32/unwind-dw2.o
In file included from ../../gcc-4.2.2/gcc/unwind-dw2.c:338:
../../gcc-4.2.2/gcc/config/i386/linux-unwind.h: In function ‘x86_fallback_frame_state’:
../../gcc-4.2.2/gcc/config/i386/linux-unwind.h:142: error: field ‘info’ has incomplete type
make[4]: *** [libgcc.mk:1191: libgcc/32/unwind-dw2.o] Error 1
make[4]: Leaving directory '/work1/jleffler/tmp/gcc-4.2.2-obj/gcc'
make[3]: *** [Makefile:1540: stmp-multilib] Error 2
make[3]: Leaving directory '/work1/jleffler/tmp/gcc-4.2.2-obj/gcc'
make[2]: *** [Makefile:4520: all-stage1-gcc] Error 2
make[2]: Leaving directory '/work1/jleffler/tmp/gcc-4.2.2-obj'
make[1]: *** [Makefile:15592: stage1-bubble] Error 2
make[1]: Leaving directory '/work1/jleffler/tmp/gcc-4.2.2-obj'
make: *** [Makefile:15876: bootstrap] Error 2

麻烦!我将把这个问题留给你来解决。您需要进行与我之前所做的类似的分析,找出

struct signify
的定义应该来自哪里:

linux-unwind.h

137     {
138       struct rt_sigframe {
139     int sig;
140     struct signify *info;
141     void *puc;
142     struct siginfo info;
143     struct context uc;
144       } *rt_ = context->cfa;
145       /* The void * cast is necessary to avoid an aliasing warning.
146          The aliasing warning is correct, but should not be a problem
147          because it does not alias anything.  */
148       sc = (struct sigcontext *) (void *) &rt_->uc.uc_mcontext;
149     }

POSIX

<signal.h>
指定:

<signal.h>
标头应将
siginfo_t
类型定义为结构体,该结构体至少应包含以下成员: ⌫

在某些系统上,标头很有可能包含

typedef struct siginfo siginfo_t;
或等效内容,并且将两次出现的
struct siginfo
更改为
siginfo_t
将修复代码。

但是,这是供您尝试的。当您尝试将 16 年前的代码移植到现代系统时,您应该预料到会遇到这样的困难,尤其是当代码像 GCC 那样与操作系统如此密切时。

© www.soinside.com 2019 - 2024. All rights reserved.