【发布时间】:2016-08-31 05:00:13
【问题描述】:
当我试图编译这样的 C 程序时:
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/time.h>
4 #include <assert.h>
5 #include "common.h"
6
7 int
8 main(int argc, char *argv[])
9 {
10 if (argc != 2) {
11 fprintf(stderr, "usage: cpu <string>\n");
12 exit(1);
13 }
14 char *str = argv[1];
15 while (1) {
16 Spin(1);
17 printf("%s\n", str);
18 }
19 return 0;
20 }
我收到一个错误
CPU.c:5:19: fatal error: common.h: No such file or directory
我已经更新了我的 gcc 编译器,所以我无法弄清楚为什么缺少“Common.h”
【问题讨论】:
-
这是来自操作系统书籍的示例。它不包括 common.h。代替 common.h 包括:
#include <unistd.h>,代替 Spin 使用sleep函数。