如何解决qemu-nox在运行make qemu-nox时在xv6的cat.c文件中引发错误
我正在尝试在xv6中实现ps命令(添加系统调用),我遵循了制作命令的过程,最后使用命令“ make 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,n) != n) {
printf(1,"cat: write error\n");
exit();
}
}
if(n < 0){
printf(1,"cat: read error\n");
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 %s\n",argv[i]);
exit();
}
cat(fd);
close(fd);
}
exit();
}
解决方法
编译器声称您正在文件cat.c的第9行上使用名为“ cps()”的函数,该函数显然不是该函数的名称。它还抱怨user.h本身存在问题。这是问题不直接在cat.c文件中,而是在标头中的某个位置(可能在user.h中)的线索。
,我发现了自己的错误,因为@Peter Maydell说错误实际上来自user.h文件,我在声明函数时错过了分号
int cps(void);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。