前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >GCC 14的一个warning to error BUG

GCC 14的一个warning to error BUG

作者头像
owent
发布2024-05-31 13:50:05
1110
发布2024-05-31 13:50:05
举报
文章被收录于专栏:owentowent

背景

早先社区报过 opentelemetry-cpp 在GCC 14中编译不通过的问题。最近我也是先升级我们项目组的工具链,主要也是把GCC升级到GCC 14,这时候发现有些第三方工具构建失败。 这里记录一下以防后续其他人碰到参考。

分析

我们在使用新版本GCC 14编译zsh的时候,报 boolcodes 和定义冲突。

分析下来发现是在 ./configure 阶段, boolcodes 这个接口的时候不通过。

./configure 里提取出来的,测试代码如下:

代码语言:javascript
复制
#include <curses.h>
#include <term.h>
int
main (void)
{
char **test = boolcodes; puts(*test);
  ;
  return 0;
}

编译命令: gcc -o conftest -I/opt/tools/include -I/opt/gcc-14/internal-packages/include -L/opt/tools/lib64 -L/opt/tools/lib -L/opt/gcc-14/lib64 -L/opt/gcc-14/lib -lncursesw -ltinfow test-source.c -lpcre -liconv -lcap -ldl -lrt -lm -lc

编译输出:

代码语言:javascript
复制
test-source.c: In function ‘main’:
test-source.c:6:15: error: initialization of ‘char **’ from incompatible pointer type ‘const char * const*’ [-Wincompatible-pointer-types]
    6 | char **test = boolcodes; puts(*test);

虽然说这里 zsh 的代码也有问题,但是可以看到。我们并没有加 -Werror 或者 -Werror=incompatible-pointer-types 它也报错了。 即便我们加了 -Wno-error (即用: gcc -o conftest -I/opt/tools/include -I/opt/gcc-14/internal-packages/include -L/opt/tools/lib64 -L/opt/tools/lib -L/opt/gcc-14/lib64 -L/opt/gcc-14/lib -lncursesw -ltinfow test-source.c -lpcre -liconv -lcap -ldl -lrt -lm -lc -Wno-error )。任然会报这个错误。

只有显式加 -Wno-error=incompatible-pointer-types 之后,输出才会变为:

代码语言:javascript
复制
test-source.c: In function ‘main’:
test-source.c:6:15: warning: initialization of ‘char **’ from incompatible pointer type ‘const char * const*’ [-Wincompatible-pointer-types]
    6 | char **test = boolcodes; puts(*test);
      |               ^~~~~~~~~

解决

最后,我给工具链脚本加了个编译选项检测来解决这类问题。

代码语言:javascript
复制
# Patch for gcc 14
for TEST_CFLAG in "-Wno-error=incompatible-pointer-types" "-Wno-error"; do
  echo "Test CFLAG: $TEST_CFLAG"
  (gcc $TEST_CFLAG -x c - -o /dev/null <<<'int main() { return 0; }' && echo "Test CFLAG: $TEST_CFLAG success" && ALL_CFLAGS="$ALL_CFLAGS $TEST_CFLAG") || echo "Test CFLAG: $TEST_CFLAG failed"
done

也不排除后面更新构建系统 cmake-toolset 的时候会发现其他外部组件有相似问题,到时候再打Patch吧。欢迎有兴趣的小伙伴互相交流研究。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-05-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 背景
  • 分析
  • 解决
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档