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

Azure Pipeline中Buildroot编译报错:类型不匹配及_STAT_VER未定义

问题

在Azure Pipeline的Ubuntu 22.04环境(gcc 9.5)中,以vsts用户在Buildroot仓库根目录执行以下脚本:

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 90 --slave /usr/bin/g++ g++ /usr/bin/g++-9
mkdir output
touch output/.br-external.mk
make my_defconfig
make

执行make时出现大量本地Ubuntu 22.04(gcc 9.4)编译时没有的警告,最终在编译libfakeroot.c时因communicate.h相关问题报错终止,核心错误信息如下:

libfakeroot.c: In function 'lremovexattr':
libfakeroot.c:100:42: error: '_STAT_VER' undeclared (first use in this function)
  100 | #define INT_NEXT_LSTAT(a,b) NEXT_LSTAT64(_STAT_VER,a,b)
      |                                          ^~~~~~~~~
fakerootconfig.h:13:45: note: in definition of macro 'NEXT_LSTAT64'
   13 | #define NEXT_LSTAT64(a,b,c) next___lxstat64(a,b,c)
      |                                             ^
libfakeroot.c:1874:5: note: in expansion of macro 'INT_NEXT_LSTAT'
 1874 |   r=INT_NEXT_LSTAT(path, &st);
      |     ^~~~~~~~~~~~~~
libfakeroot.c: In function 'fremovexattr':
libfakeroot.c:101:42: error: '_STAT_VER' undeclared (first use in this function)
  101 | #define INT_NEXT_FSTAT(a,b) NEXT_FSTAT64(_STAT_VER,a,b)
      |                                          ^~~~~~~~~
fakerootconfig.h:11:45: note: in definition of macro 'NEXT_FSTAT64'
   11 | #define NEXT_FSTAT64(a,b,c) next___fxstat64(a,b,c)
      |                                             ^
libfakeroot.c:1895:5: note: in expansion of macro 'INT_NEXT_FSTAT'
 1895 |   r=INT_NEXT_FSTAT(fd, &st);
      |     ^~~~~~~~~~~~~~
libfakeroot.c: In function 'fts_read':
libfakeroot.c:1959:22: warning: passing argument 1 of 'send_get_stat64' from incompatible pointer type [-Wincompatible-pointer-types]
 1959 |     SEND_GET_STAT64(r->fts_statp, _STAT_VER);
      |                     ~^~~~~~~~~~~
      |                      |
      |                      struct stat *
libfakeroot.c:89:46: note: in definition of macro 'SEND_GET_STAT64'
   89 | #define SEND_GET_STAT64(a,b) send_get_stat64(a)
      |                                              ^
In file included from libfakeroot.c:60:
communicate.h:209:44: note: expected 'struct stat64 *' but argument is of type 'struct stat *'
 209 | extern void send_get_stat64(struct stat64 *buf);
      |                             ~~~~~~~~~~~~~~~^~~

解决方案

1. 补全_STAT_VER宏定义

_STAT_VER是glibc提供的扩展宏,报错是因为未正确引入。在libfakeroot.c的头部添加如下代码(确保_GNU_SOURCE定义在<sys/stat.h>之前):

#define _GNU_SOURCE
#include <sys/stat.h>

这个宏会启用glibc的扩展功能,包含_STAT_VER的定义。

2. 修复指针类型不兼容问题

报错显示struct stat*与struct stat64*类型不匹配,有两种解决方式:

  • 快速修复:添加类型转换
    修改libfakeroot.c中的SEND_GET_STAT64宏,强制转换参数类型:
    #define SEND_GET_STAT64(a,b) send_get_stat64((struct stat64*)a)
    
  • 彻底修复:统一使用stat64类型
    将libfakeroot.c中所有struct stat类型的变量替换为struct stat64,确保与communicate.h中函数声明的参数类型一致。

3. 调整Buildroot编译环境

本地gcc 9.4正常但Azure的gcc 9.5报错,大概率是版本适配问题:

  • 升级Buildroot到最新稳定版,新版本通常会修复工具链兼容性bug。
  • 若无法升级,执行make前添加环境变量启用大文件支持:
    export CFLAGS="-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE"
    make
    

4. 优化工具链切换方式

当前用update-alternatives全局切换gcc可能导致环境变量异常,建议直接指定编译工具路径:

make CC=/usr/bin/gcc-9 CXX=/usr/bin/g++-9 my_defconfig
make CC=/usr/bin/gcc-9 CXX=/usr/bin/g++-9

这种方式更可靠,不会影响系统其他工具的gcc版本。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 04:45:17