静水流深。 发表于 2013-08-06 21:33

错误:sys/types.h :没有那个文件或目录 ,菜鸟求解


Linux新手报道,像各位道友问声好。本人菜鸟一只,今天照着书上写了程序,用gcc编译,出现了错误提示:
# gcc -Wall -o process process.c
process.c:15:24: 错误:sys/types.h :没有那个文件或目录

但是我去/usr/include/能找到types.h这个文件
求各位大神指点哈,在此感激不尽。

书上的代码如下:

/*
* Copyright (c) 2009-~ Hu bin
*
* This source code is released for free distribution under the terms of the
* GNU General Public License
*
* Author:       Hu Bin<hb198708@gmail.com>
* Created Time: 2013年08月06日 星期二 21时59分26秒
* File Name:    process.c
*
* Description:
*/

#include <stdio.h>
#include <sys/types.h >
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
      pid_t id;
      id = fork();
      if(id<0)
      {
                printf("fork error!\n");
                exit(1);
      }
      else if(id==0)
      {
                printf("I am the son of my father,my name is %d\n",getpid());
      }
      else
      {
                printf("I am the father,my name is %d\n",getpid());
      }
      exit(0);
}

2007robot 发表于 2013-08-07 20:34

#include <stdio.h>
#include <linux/types.h>
#include <stdlib.h>
#include <unistd.h>
我在Uuntu 12.04上修改后编译通过,好像Ubuntu的发行版把types.h文件放在/usr/include/linux/ 路径下了,其它的发行版我就不清楚了。

你应该在/usr/include/sys下找types.h文件,你代码报错,估计是找不到(不是在/usr/include/ 目录下找types.h这个文件),你再看一下。
页: [1]
查看完整版本: 错误:sys/types.h :没有那个文件或目录 ,菜鸟求解