You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CentOS7编译GCC 14.2.0时遇max_align_t未知类型错误求助

编译GCC 14.2.0时gettext报错的解决方法

问题概述

在CentOS7系统中从源码编译GCC 14.2.0,执行make过程中gettext模块抛出max_align_t未定义的编译错误。

错误详情

gcc -std=gnu99 -DHAVE_CONFIG_H -DEXEEXT="" -I. -I../../../gcc-14.2.0/gettext/gettext-runtime/gnulib-lib -I..  -I../intl -I../../../gcc-14.2.0/gettext/gettext-runtime/intl -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1   -Wno-cast-qual -Wno-conversion -Wno-float-equal -Wno-sign-compare -Wno-undef -Wno-unused-function -Wno-unused-parameter -Wno-pedantic -Wno-sign-conversion -Wno-type-limits -Wno-unsuffixed-float-constants -g -c -o unistr/libgrt_a-u8-uctomb.o `test -f 'unistr/u8-uctomb.c' || echo '../../../gcc-14.2.0/gettext/gettext-runtime/gnulib-lib/'`unistr/u8-uctomb.c
In file included from ../../../gcc-14.2.0/gettext/gettext-runtime/gnulib-lib/scratch_buffer.h:115:0,
                 from ../../../gcc-14.2.0/gettext/gettext-runtime/gnulib-lib/malloc/scratch_buffer_grow.c:23:
./malloc/scratch_buffer.gl.h:70:9: error: unknown type name ‘max_align_t’
   union { max_align_t __align; char __c[1024]; } __space;
         ^

当前环境信息

  • gettext版本:
# gettext --version
gettext (GNU gettext-runtime) 0.22
Copyright (C) 1995-2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Ulrich Drepper.
  • 系统:CentOS7

编译步骤

yum groupinstall -y "Development Tools"
yum install -y wget bzip2 tar

GCC_VERSION=14.2.0
wget https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
tar -xvzf gcc-$GCC_VERSION.tar.gz
cd gcc-$GCC_VERSION

./contrib/download_prerequisites
mkdir ../gcc-build
cd ../gcc-build
../gcc-$GCC_VERSION/configure --enable-languages=c,c++ --disable-multilib

make -j$(nproc)
make install

可行解决方案

方案一:临时定义max_align_t类型

CentOS7默认的GCC 4.8.5在gnu99标准下不会自动识别C11引入的max_align_t类型,可在configure时通过CFLAGS强制定义:

CFLAGS="-Dmax_align_t=__max_align_t" ../gcc-$GCC_VERSION/configure --enable-languages=c,c++ --disable-multilib

之后重新执行make -j$(nproc)和make install。

方案二:先升级系统编译器(推荐)

用较新版本的GCC编译GCC 14.2.0能避免更多兼容性问题,步骤如下:

  1. 安装CentOS SCL源:
yum install -y centos-release-scl
  1. 安装GCC 9工具链:
yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++
  1. 启用GCC 9环境:
scl enable devtoolset-9 bash
  1. 重新执行原编译流程(从configure步骤开始即可)。

方案三:修改报错头文件(临时hack)

找到编译目录下的./malloc/scratch_buffer.gl.h,在文件开头添加:

#ifndef max_align_t
#define max_align_t __max_align_t
#endif

此方法仅解决当前报错,后续可能出现其他兼容性问题,不推荐长期使用。

内容的提问来源于stack exchange,提问作者shashashamti2008

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 17:49:50