C++ 错误:sys/wait.h:没有那个文件或目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18013950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: sys/wait.h: No such file or directory
提问by Thangnv
I'm trying to code a simple shell by C. But i can't using sys/wait.h. My code same that:
我正在尝试用 C 编写一个简单的 shell。但是我不能使用 sys/wait.h。我的代码相同:
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main(void) {
char command[BUFSIZ];
int status;
pid_t pid;
for(;;) {
printf("simpsh: ");
if(fgets(command, sizeof(command), stdin) == NULL) {
printf("\n");
return 0;
}
command[strlen(command) - 1] = '[Error] sys/wait.h: No such file or directory
';
if((pid = fork()) == 0)
execlp(command, command, 0);
while(wait(&status) != pid)
continue;
printf("\n");
}
}
}
I'm using dev-C++ and result is:
我正在使用 dev-C++,结果是:
##代码##What wrong in here? And if anyone have some suggestions for me to create a simple shell by C or C++ please give me some links or codes. thanks!
这里有什么问题?如果有人对我用 C 或 C++ 创建一个简单的 shell 有一些建议,请给我一些链接或代码。谢谢!
回答by someone
From http://sourceforge.net/p/dev-cpp/discussion/48211/thread/e32720b4
来自http://sourceforge.net/p/dev-cpp/discussion/48211/thread/e32720b4
TextTiling/util.c:8:22: sys/wait.h: No such file or directory TextTiling/util.c:26:21: sys/vfs.h: No such file or directory
TextTiling/util.c:8:22: sys/wait.h: 没有那个文件或目录 TextTiling/util.c:26:21: sys/vfs.h: 没有那个文件或目录
These are OS specific files, but are not Windows headers. Windows does not fully support POSIX APIs. You will probably have to do some porting of the code to get it to compile and run on Windows.
这些是操作系统特定的文件,但不是 Windows 头文件。Windows 不完全支持 POSIX API。您可能需要对代码进行一些移植才能使其在 Windows 上编译和运行。
You will probably have more luck building it in its intended environment (Linux or OSX perhaps, either way a UNIX-like environment). You might be able to build it under Cygwin, but that is a sledgehammer for a nut.
在其预期的环境(Linux 或 OSX,也许是类 UNIX 环境)中构建它,您可能会更幸运。您也许可以在 Cygwin 下构建它,但这对坚果来说是一把大锤。
A simple(ish) solution is to run Linux under a Virtual Machine (using VMWare's free VMPlayer or VMServer tools for example). And then build and run teh code in a VM. The VM can access the Windows machine via a virtual network, so you can still get results and data uinto the Windows environment if you wish.
一个简单的(ish)解决方案是在虚拟机下运行 Linux(例如使用 VMWare 的免费 VMPlayer 或 VMServer 工具)。然后在 VM 中构建和运行代码。VM 可以通过虚拟网络访问 Windows 机器,因此您仍然可以根据需要将结果和数据输入到 Windows 环境中。
On a diferent issue, Dev-C++ will sometimes (and apparently randomly) fail when projects are in sub-folders of its installation directory (C:\Dev-Cpp).
在另一个问题上,当项目位于其安装目录 (C:\Dev-Cpp) 的子文件夹中时,Dev-C++ 有时会(并且显然是随机的)失败。