致命错误:在 mac osx 10.10.5 下找不到“common.h”文件

att*_*lee 6 c c++ macos

我按照操作系统:三件简单的书,介绍章节中的代码,

#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <assert.h>
#include "common.h"

int
main(int argc, char *argv[])
{
  if (argc != 2)
  {
    fprintf(stderr, "usage: cpu <string>\n");
    exit(1);
  }
  char *str = argv[1];
  while(1)
  {
    Spin(1);
    printf("%s\n", str);
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试时gcc -o cpu cpu.c -Wall

错误出来了:fatal error: 'common.h' file not found

我试过从这个链接下载common.h ,并把这个文件和cpu.c放在一起,但它不起作用,错误信息:

cpu.c:8:1: error: conflicting types for 'main'
main(int argc, char *argv[])
^
./common.h:86:13: note: previous declaration is here
extern int              main(int, char **, char **);
                        ^
cpu.c:18:5: warning: implicit declaration of function 'Spin' is invalid in C99 [-Wimplicit-function-declaration]
    Spin(1);
    ^
1 warning and 1 error generated.
Run Code Online (Sandbox Code Playgroud)

如何修复错误?谢谢。

Eri*_*rik 5

"common.h"此问题的标题在第 1 章旁边的课程目录中链接为 tgz 包:http : //pages.cs.wisc.edu/~remzi/OSTEP/

将其放在源文件旁边,然后再次尝试编译。

  • 为什么不直接添加链接`http://pages.cs.wisc.edu/~remzi/OSTEP/Code/code.intro.tgz` (8认同)