【发布时间】:2012-03-25 14:53:34
【问题描述】:
这是我的代码(创建只是为了测试 fork()):
#include <stdio.h>
#include <ctype.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int pid;
pid=fork();
if (pid==0) {
printf("I am the child\n");
printf("my pid=%d\n", getpid());
}
return 0;
}
我收到以下警告:
warning: implicit declaration of function 'fork'
undefined reference to 'fork'
这有什么问题?
【问题讨论】:
-
您是否安装了 C 库的头文件?你是如何调用你的编译器的?
-
gcc test.c -pedantic -Wall -o test.exe
-
你确定 fork() 是 stdio.h 的一部分吗?它不是根据cplusplus.com/reference/clibrary/cstdio。可能与您包含的另一个头文件有冲突?
-
显然它是
的一部分,它怎么会与我包含的内容冲突? -
@user1166935:您使用的是什么操作系统?是否有可能由于某种原因您的
unistd.h文件不好?