gpt4 book ai didi

c - Windows 操作系统中 Code::Blocks 编辑器中对 fork() 的 undefined reference

转载 作者:可可西里 更新时间:2023-11-01 12:43:02 26 4
gpt4 key购买 nike

当我在 Windows 操作系统的 Code::Blocks 中运行以下代码时。我曾经收到一个错误,称为对 fork() 的 undefined reference 。我确实设置/选择了 GCC 编译器作为我的默认编译器。

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

请帮我看看,我可以在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);;
}
}

这里它给出了对 sleep() 和/* delay also */的 undefined reference 。
请帮助我。

最佳答案

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

2017 年更新:这些天我们还有 Windows Subsystem for Linux .

关于c - Windows 操作系统中 Code::Blocks 编辑器中对 fork() 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8819673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com