运行make-qemu-nox时,qemu-ox在xv6中的cat.c文件中引发错误



我正在尝试在xv6中实现ps命令(添加系统调用(,我遵循了制作一个命令的过程,最后使用命令"使qemu-nox";为了最终测试系统调用,我得到了以下错误

gcc -fno-pic -static -fno-builtin -fno-strict-aliasing -O2 -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie -no-pie   -c -o cat.o cat.c
cat.c: In function ‘cps’:
cat.c:9:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
9 | {
| ^
cat.c:23:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
23 | {
| ^
In file included from cat.c:3:
user.h:26:5: error: old-style parameter declarations in prototyped function definition
26 | int cps(void)
|     ^~~
cat.c:40: error: expected ‘{’ at end of input
40 | }
| 
cat.c:40: error: control reaches end of non-void function [-Werror=return-type]
40 | }
| 
cc1: all warnings being treated as errors
make: *** [<builtin>: cat.o] Error 1

这是cat.c文件,一切看起来都很好,但我不明白为什么它显示错误

#include "types.h"
#include "stat.h"
#include "user.h"
char buf[512];
void
cat(int fd)
{
int n;
while((n = read(fd, buf, sizeof(buf))) > 0) {
if (write(1, buf, n) != n) {
printf(1, "cat: write errorn");
exit();
}
}
if(n < 0){
printf(1, "cat: read errorn");
exit();
}
}
int
main(int argc, char *argv[])
{
int fd, i;
if(argc <= 1){
cat(0);
exit();
}
for(i = 1; i < argc; i++){
if((fd = open(argv[i], 0)) < 0){
printf(1, "cat: cannot open %sn", argv[i]);
exit();
}
cat(fd);
close(fd);
}
exit();
}

编译器声称您在一个名为"cps(("在文件cat.c的第9行,显然不是该函数的名称。它也在抱怨user.h本身的一个问题。这表明问题不是直接出现在你的cat.c文件中,而是在它包含的头文件中的某个地方(可能在user.h中(

我发现了我的错误,因为@Peter Maydell说错误实际上来自用户.h文件,我在声明函数时漏掉了一个分号

int cps(void);

最新更新