编译问题:GCC 安装与配置
# 一、在 Ambari 项目中编译 ambari-web
时的 GCC 版本问题
# 1.1 编译时报错日志
在编译 ambari-web
时,如果遇到如下报错,通常是因为系统中 GCC 版本较低,无法满足 Node.js 的依赖需求:
[DEBUG] Loading mojo com.github.eirslett:frontend-maven-plugin:1.4:yarn from plugin realm ClassRealm[plugin>com.github.eirslett:frontend-maven-plugin:1.4, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[DEBUG] Configuring mojo execution 'com.github.eirslett:frontend-maven-plugin:1.4:yarn:yarn install' with basic configurator -->
[DEBUG] (f) arguments = install --ignore-engines --pure-lockfile --verbose
[DEBUG] (f) environmentVariables = {npm_config_tmp=/tmp/npm_config_tmp}
[DEBUG] (f) npmRegistryURL = https://registry.npmmirror.com
[DEBUG] (f) project = MavenProject: org.apache.ambari:ambari-web:2.8.0.0.0 @ /opt/modules/ambari/ambari-web/pom.xml
[DEBUG] (f) repositorySystemSession = org.eclipse.aether.DefaultRepositorySystemSession@3c35c345
[DEBUG] (f) session = org.apache.maven.execution.MavenSession@41aaedaa
[DEBUG] (f) skip = false
[DEBUG] (f) skipTests = false
[DEBUG] (f) testFailureIgnore = false
[DEBUG] (f) workingDirectory = /opt/modules/ambari/ambari-web
[DEBUG] (f) yarnInheritsProxyConfigFromMaven = false
[DEBUG] (f) execution = com.github.eirslett:frontend-maven-plugin:1.4:yarn {execution: yarn install}
[DEBUG] -- end configuration --
[INFO] yarn not inheriting proxy config from Maven
[INFO] Running 'yarn install --ignore-engines --pure-lockfile --verbose --registry=https://registry.npmmirror.com/' in /opt/modules/ambari/ambari-web
[DEBUG] Executing command line [/opt/modules/ambari/ambari-web/node/yarn/dist/bin/yarn, install, --ignore-engines, --pure-lockfile, --verbose, --registry=https://registry.npmmirror.com]
[ERROR] node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
[ERROR] node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by node)
[ERROR] node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)
[ERROR] node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by node)
[ERROR] node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by node)
[ERROR] node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by node)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.140 s
[INFO] Finished at: 2024-08-20T09:15:00+08:00
[INFO] ------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
这类问题通常与系统中的 GCC 版本过低有关,导致 Node.js 的依赖无法满足。
# 1.2 解决方案
# 1.2.1 使用多版本 GCC 共存
为了解决编译时因 GCC 版本过低导致的报错,我们可以启用 SCL(Software Collection)源来安装更高版本的 GCC。你可以通过以下步骤来实现:
启用
devtoolset-7
(包含较新的 GCC 版本):scl enable devtoolset-7 bash
1安装
devtoolset-7-gcc
和devtoolset-7-gcc-c++
:yum install devtoolset-7-gcc devtoolset-7-gcc-c++
1
通过这种方式,你可以在当前系统中使用较新的 GCC 版本,而不需要替换掉系统自带的低版本 GCC。
提示
启用 SCL 后,系统会使用 devtoolset-7
提供的 GCC,而不会影响系统中其他工具的正常使用。这使得多版本共存成为可能,解决了版本兼容问题。
# 1.2.2 配置示例
配置 YUM 仓库并启用对应版本的 GCC,确保安装最新版的编译工具链。
在项目中配置好相应的编译环境后,执行以下命令:
scl enable devtoolset-7 bash
1
注意
确保你在执行命令时已经正确配置了 SCL 环境,否则可能无法正确启用高版本 GCC。
通过这些步骤,你可以解决由于 GCC 版本过低引起的编译问题,并成功编译项目。
本文提供的解决方案适用于需要使用新版 GCC 的系统,实际操作中可能会根据系统环境有所不同。如果遇到问题,欢迎留言讨论。贡献