在使用../configure --prefix=/usr/local命令时,出现问题如下:
[root@localhost build]# ../configure --prefix=/usr/local
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... -std=gnu11
checking for g++... g++
checking whether the compiler supports GNU C++... yes
checking whether g++ accepts -g... yes
checking for g++ option to enable C++11 features... -std=gnu++11
checking whether g++ -std=gnu++11 can link programs... no
checking for sysdeps preconfigure fragments... aarch64 alpha arc arm csky hppa i386 loongarch m68k microblaze checking for egrep -e... /usr/bin/grep -E
mips or1k powerpc riscv s390 sh checking for egrep -e... (cached) /usr/bin/grep -E
sparc x86_64 checking whether gcc -std=gnu11 compiles in -mx32 mode by default... no
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking for ld... ld
checking version of ld... 2.27, ok
checking for gnumake... no
checking for gmake... gmake
checking version of gmake... 4.4, ok
checking for gnumsgfmt... no
checking for gmsgfmt... no
checking for msgfmt... msgfmt
checking version of msgfmt... 0.19.8.1, ok
checking for makeinfo... makeinfo
checking version of makeinfo... 5.1, ok
checking for sed... sed
checking version of sed... 4.2.2, ok
checking for gawk... gawk
checking version of gawk... 4.0.2, ok
checking for bison... bison
checking version of bison... 3.0.4, ok
checking if gcc -std=gnu11 is sufficient to build libc... no
checking for python3... python3
checking version of python3... 3.12.8, ok
configure: error:
*** These critical programs are missing or too old: compiler
*** Check the INSTALL file for required versions.
根据以上日志,配置失败的原因主要涉及 C/C++ 编译器链接失败(g++ -std=gnu++11 can link programs... no 和 checking if gcc -std=gnu11 is sufficient to build libc... no)。
以下是详细的解决方案:
1. 升级 GCC 和 G++ 到现代版本
从日志看,系统默认的 GCC 版本可能过旧,导致不支持必要的编译特性。升级方法:
(1) 安装高版本 GCC 和 G++
对于 CentOS 7/8:
# 安装开发工具链和 SCL 仓库(确保已修复之前的仓库错误)
sudo yum install centos-release-scl
sudo yum install devtoolset-11-gcc devtoolset-11-gcc-c++
# 激活新编译器版本
scl enable devtoolset-11 bash
gcc --version # 确认 GCC ≥ 11.0
(2) 可选:从源码编译最新 GCC
若仍需更高版本(需要至少 30 分钟):
cd /tmp
wget https://ftp.gnu.org/gnu/gcc/gcc-14.2.0/gcc-14.2.0.tar.gz
tar xzf gcc-14.2.0.tar.gz
cd gcc-14.2.0
./contrib/download_prerequisites
mkdir build && cd build
../configure --prefix=/usr/local --disable-multilib --enable-languages=c,c++
make -j$(nproc)
sudo make install
# 更新动态库缓存
sudo ldconfig
2. 安装 C++ 标准库开发包
确保安装了完整的 C++ 运行时库:
sudo yum install libstdc++-devel
3. 检查编译器功能完整性
手动验证编译器是否能链接程序:
(1) 测试 C 编译器
echo 'int main(){ return 0; }' > test.c
gcc -std=gnu11 test.c -o test
./test # 成功应无输出
(2) 测试 C++ 编译器
echo 'int main(){ return 0; }' > test.cpp
g++ -std=gnu++11 test.cpp -o test
./test # 成功应无输出
- 若失败:
检查环境变量PATH和LD_LIBRARY_PATH是否包含新编译器路径(如/usr/local/bin或/opt/rh/devtoolset-11/root/usr/bin)。
4. 确认依赖工具链完整性
安装可能的缺失工具:
(1) 安装 makeinfo(属于 texinfo 包)
sudo yum install texinfo
(2) 安装其他必要开发工具
sudo yum install autoconf automake libtool glibc-devel binutils kernel-headers
5. 修复 config.log 中的关键错误
查看 config.log 的尾部,筛选实际错误位置:
# 在构建目录中执行
grep -A 50 -B 5 'error: required' config.log
常见错误模式及修复:
(1) 缺少 64 位库支持
如果看到 libstdc++.so not found 或 -m64 错误:
sudo yum install glibc-devel.x86_64
(2) 编译器测试程序无法链接
如果测试程序未找到 crt1.o 等文件,可能是路径问题:
# 查找缺失的库路径
find /usr/lib -name crt1.o
# 添加路径到 LIBRARY_PATH
export LIBRARY_PATH=/usr/lib64:$LIBRARY_PATH
6. 重新配置并指定编译器(针对性修正)
若已安装新版本的 GCC/G++ 但未自动识别,手动指定路径:
# 假设新编译器路径为 /opt/rh/devtoolset-11/root/usr/bin
export CC=/opt/rh/devtoolset-11/root/usr/bin/gcc
export CXX=/opt/rh/devtoolset-11/root/usr/bin/g++
../configure --prefix=/usr/local
关键点总结
- 编译器版本过低:需升级到支持 C11/C++11 的版本(如 GCC ≥ 4.8,但建议 ≥ 11)。
- C++ 运行时库缺失:安装
libstdc++-devel确保链接能力。 - 工具链不完整:补全
texinfo、autoconf等开发工具。
完成后,重新运行配置命令即可正常通过检测! 🔧
1947




被折叠的 条评论
为什么被折叠?



