qemu-nox 在 xv6 中的 cat.c 文件中抛出错误,而 运行 make qemu-nox
qemu-nox throws errors in cat.c file in xv6 while running make qemu-nox
我正在尝试在 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, buf, 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 文件中,而是出在 headers 文件中的某处(可能在 user.h 中)。
我发现了我的错误,因为@Peter Maydell 说错误实际上来自 user.h 文件,我在声明函数
时错过了 semi-colon
int cps(void);
我正在尝试在 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, buf, 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 文件中,而是出在 headers 文件中的某处(可能在 user.h 中)。
我发现了我的错误,因为@Peter Maydell 说错误实际上来自 user.h 文件,我在声明函数
时错过了 semi-colonint cps(void);