gpt4 book ai didi

c - 如何在 OS X 上使用 --pedantic-errors 进行编译?

转载 作者:太空宇宙 更新时间:2023-11-03 23:57:20 25 4
gpt4 key购买 nike

这是一个简单的 C 文件:

#include <stdio.h>
#include <stdlib.h>

int
main() {
printf("hi there!\n");
return 0;
}

使用 gcc -ansi -pedantic -pedantic-errors 编译会得到:

In file included from /usr/include/i386/_structs.h:38,
from /usr/include/machine/_structs.h:31,
from /usr/include/sys/_structs.h:57,
from /usr/include/sys/signal.h:154,
from /usr/include/sys/wait.h:116,
from /usr/include/stdlib.h:65,
from test.c:2:
/usr/include/mach/i386/_structs.h:91: error: type of bit-field ‘__invalid’ is a GCC extension

关于 GCC 扩展的更多错误。我知道我可以删除 -pedantic-errors 开关并重新编译,但出于一个和另一个原因,这不在卡片中。有没有办法克服这个错误?也许下载并安装另一个 C 库?我在本地处理需要在远程计算机上编译的代码,因此很遗憾,我无法将 Makefile 设置为指向特殊的库位置。

最佳答案

您可以修改/usr/include/mach/i386/_structs.h:91 以使用 __extension__关键词。尽管您可能想知道为什么情况并非如此。

另一种文件级解决方案是添加一个#pragma GCC system_header _structs.h 顶部的指令。

要在构建级别修复它,请添加 -isystem /usr/include/mach/i386/到编译器选项。然后,该文件夹中的所有 header 都将被包含在内,就好像它们是系统 header 一样(应该已经是这种情况,但显然不是)。

关于c - 如何在 OS X 上使用 --pedantic-errors 进行编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2320559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com