2022 年在 Ubuntu 21.10 上安装 gcc-4.8

2022 年在 Ubuntu 21.10 上安装 gcc-4.8

我正在尝试在 Ubuntu 21.10 上安装 GCC-4.8。

首先,我尝试从存储库安装,但失败了,可能是因为 4.8 版本太旧:

>sudo apt-get install python-software-properties
>sudo add-apt-repository ppa:ubuntu-toolchain-r/test
>sudo apt-get update
>sudo apt-get install gcc-4.8

最后一个命令的输出是:

>sudo apt-get install gcc-4.8
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'gcc-4.8-hppa64' for regex 'gcc-4.8'
The following package was automatically installed and is no longer required:
  libfwupdplugin1
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

其次,我尝试从源代码进行编译。我运行了以下命令:

>wget http://www.netgull.com/gcc/releases/gcc-4.8.0/gcc-4.8.0.tar.bz2
>tar xjf gcc-4.8.0.tar.bz2 
>sudo apt-get install libgm
>cd gcc-4.8.0/
>./contrib/download_prerequisites 
>./configure --prefix=/app/gcc/4.8.0
>make -j 8

但最终我得到了这个错误:

In file included from ./tm.h:42,
                 from ../.././gcc/cp/init.c:26:
../.././gcc/defaults.h:126:24: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
  126 |       fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n",  \
      |                        ^
../.././gcc/cp/except.c: In function ‘int doing_eh()’:
../.././gcc/cp/except.c:468:11: warning: unquoted option name ‘-fexceptions’ in format [-Wformat-diag]
  468 |    error ("exception handling disabled, use -fexceptions to enable");
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../.././gcc/cp/except.c:1005:
cfns.gperf: At global scope:
cfns.gperf:101:1: error: ‘const char* libc_name_p(const char*, unsigned int)’ redeclared inline with ‘gnu_inline’ attribute
cfns.gperf:26:14: note: ‘const char* libc_name_p(const char*, unsigned int)’ previously declared here
cfns.gperf:26:14: warning: inline function ‘const char* libc_name_p(const char*, unsigned int)’ used but never defined
make[3]: *** [Makefile:1058: cp/except.o] Error 1
make[3]: *** Waiting for unfinished jobs....
../.././gcc/cp/friend.c: In function ‘tree_node* do_friend(tree, tree, tree, tree, overload_flags, bool)’:
../.././gcc/cp/friend.c:590:15: warning: unquoted sequence of 2 consecutive punctuation characters ‘<>’ in format [-Wformat-diag]
  590 |      "and add <> after the function name here) ");
      |               ^~
../.././gcc/cp/friend.c:590:47: warning: spurious trailing space in format [-Wformat-diag]
  590 |      "and add <> after the function name here) ");
      |                                               ^
../.././gcc/cp/init.c: In function ‘tree_node* build_java_class_ref(tree)’:
../.././gcc/cp/init.c:3028:10: warning: contraction ‘can%'t’ in format; use ‘cannot’ instead [-Wformat-diag]
 3028 |  error ("can%'t find %<class$%> in %qT", type);
      |          ^~~~~~
rm gcc.pod
make[3]: Leaving directory '/home/sda/Program_files/gcc-build/gcc-4.8.0/host-x86_64-unknown-linux-gnu/gcc'
make[2]: *** [Makefile:4163: all-stage1-gcc] Error 2
make[2]: Leaving directory '/home/sda/Program_files/gcc-build/gcc-4.8.0'
make[1]: *** [Makefile:23575: stage1-bubble] Error 2
make[1]: Leaving directory '/home/sda/Program_files/gcc-build/gcc-4.8.0'
make: *** [Makefile:892: all] Error 2

我的 gcc 是“gcc 版本 10.3.0 (Ubuntu 10.3.0-11ubuntu1)”。我猜想新的 GCC 编译器无法构建这么旧的编译器。

请指教。

=============================================

跟进

我尝试遵循下面给出的建议,并在不同的文件夹中重新编译 - 相同的输出,一个错误,但是不同。

我使用了以下命令:

tar xjf gcc-4.8.0.tar.bz2 
./gcc-4.8.0/contrib/download_prerequisites 
mkdir build
cd build/
../gcc-4.8.0/configure --prefix=/usr/local/gcc-4.8.0
make -j 16

输出为:

../../gcc-4.8.0/gcc/cp/semantics.c: In function ‘tree_node* finish_omp_clauses(tree)’:
../../gcc-4.8.0/gcc/cp/semantics.c:4150:16: warning: unquoted identifier or keyword ‘num_threads’ in format [-Wformat-diag]
 4150 |        error ("num_threads expression must be integral");
      |                ^~~~~~~~~~~
../../gcc-4.8.0/gcc/cp/semantics.c: In function ‘tree_node* finish_trait_expr(cp_trait_kind, tree, tree)’:
../../gcc-4.8.0/gcc/cp/semantics.c:5614:15: warning: unquoted identifier or keyword ‘__is_convertible_to’ in format [-Wformat-diag]
 5614 |       sorry ("__is_convertible_to");
      |               ^~~~~~~~~~~~~~~~~~~
../../gcc-4.8.0/gcc/cp/semantics.c: In function ‘tree_node* cxx_eval_call_expression(const constexpr_call*, tree, bool, bool, bool*, bool*)’:
../../gcc-4.8.0/gcc/cp/semantics.c:6797:10: warning: unquoted option name ‘-fconstexpr-depth’ in format [-Wformat-diag]
 6797 |         "-fconstexpr-depth= to increase the maximum)",
      |          ^~~~~~~~~~~~~~~~~
../../gcc-4.8.0/gcc/cp/semantics.c: In function ‘tree_node* finish_decltype_type(tree, bool, tsubst_flags_t)’:
../../gcc-4.8.0/gcc/cp/semantics.c:5326:11: warning: this statement may fall through [-Wimplicit-fallthrough=]
 5326 |           if (DECL_BIT_FIELD_TYPE (expr))
      |           ^~
../../gcc-4.8.0/gcc/cp/semantics.c:5333:9: note: here
 5333 |         case FUNCTION_DECL:
      |         ^~~~
../../gcc-4.8.0/gcc/cp/semantics.c: In function ‘bool potential_constant_expression_1(tree, bool, tsubst_flags_t)’:
../../gcc-4.8.0/gcc/cp/semantics.c:8640:7: warning: this statement may fall through [-Wimplicit-fallthrough=]
 8640 |       if (!literal_type_p (TREE_TYPE (t)))
      |       ^~
../../gcc-4.8.0/gcc/cp/semantics.c:8650:5: note: here
 8650 |     case INIT_EXPR:
      |     ^~~~
rm gcc.pod
make[3]: Leaving directory '/home/sda/Program_files/gcc-build/build/gcc'
make[2]: *** [Makefile:4157: all-stage1-gcc] Error 2
make[2]: Leaving directory '/home/sda/Program_files/gcc-build/build'
make[1]: *** [Makefile:21520: stage1-bubble] Error 2
make[1]: Leaving directory '/home/sda/Program_files/gcc-build/build'
make: *** [Makefile:886: all] Error 2

还有其他建议吗?

我个人的直觉是,问题出在用于编译 GCC v. 4.8.0 的 GCC v. 10.3.1 上。新 GCC 可能与旧源代码不兼容。

请指教

相关内容