预处理器编译 C 程序时缺少二元运算符的错误

预处理器编译 C 程序时缺少二元运算符的错误

我尝试升级到 Ubuntu 18.04 并使用从终端编译一个简单的 C 程序gcc -o test test.c

#include <stdio.h>
void main() {
    printf("h\n");
}

但它引发了一个missing binary operator before token "("错误。

in file included from /usr/local/include/features.h:375:0 
from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33 
from /usr/include/stdio.h:27 
from test.c:1

/usr/include/x86_64-linux-gnu/sys/cdef.h:467:79: error :missing binary operator before token "(" 
#if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)

In file included from test.c:1:0:
/usr/include/stdio.h:276:43: error: missing binary operator before token "(" 
#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB (LIB_EXT2)

gcc 版本 7.5.0

答案1

18.04 的当前默认 gcc 版本是 7.4,而不是 7.5。运行find /usr/include/ -name "stdio.h"。结果应该包括/usr/include/stdio.h并类似但不一定与此相同:

$查找 /usr/include/-name“stdio.h”
/usr/include/bsd/stdio.h
/usr/include/x86_64-linux-gnu/bits/stdio.h
/usr/include/stdio.h
/usr/include/c++/7/tr1/stdio.h
/usr/include/c++/8/tr1/stdio.h

如果没有返回结果,请运行以下命令:

sudo apt install --reinstall gcc build-essential

相关内容