加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 致命错误:在mac osx 10.10.5下找不到’common.h’文件

发布时间:2020-12-16 07:13:46 所属栏目:百科 来源:网络整理
导读:我按照操作系统:三个简单的部分,introduction chapter中的代码, #include stdio.h#include stdlib.h#include sys/time.h#include assert.h#include "common.h"intmain(int argc,char *argv[]){ if (argc != 2) { fprintf(stderr,"usage: cpu stringn"); ex
我按照操作系统:三个简单的部分,introduction chapter中的代码,

#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("%sn",str);
  }
  return 0;
}

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

出现错误:致命错误:找不到’common.h’文件,

我尝试从this link下载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.

如何修复错误?谢谢.

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读