Windows操作系统中Code :: Blocks编辑器中对fork()的未定义引用

Ras*_*yak 9 c windows compiler-construction gcc codeblocks

当我在Windows操作系统中的Code :: Blocks中运行代码时.我曾经得到一个名为对fork()的未定义引用的错误.我确实设置/选择GCC编译器作为我的默认编译器.

#include<stdio.h>       
#include<unistd.h>          
void main()          
{       
 int x;       
 x = 0;       
 fork();       
 x = 1;        
 ...     
 ....    
}
Run Code Online (Sandbox Code Playgroud)

请帮帮我告诉我,我可以在Windows环境下的Code :: Blocks中使用unix/linux程序吗?

我写了另一个程序,

main()
{
  int x = 0;
  if(x == 0)
  {
    printf("X = %d", x);
    sleep(1000);//used delay also
    x = 1;
    printf("Now X = %d", x);;
  }
}
Run Code Online (Sandbox Code Playgroud)

在这里它给eroor提供了对sleep()和/*延迟的未定义引用*/.
请帮我.

cha*_*ite 9

不,无论你使用什么IDE,你都不能在Windows上编写Unix代码.但是,您应该尝试使用cygwin,这应该提供您需要的兼容性层.

2017更新:这些天我们还有Windows的Solaris子系统.