我得到了一本新的编程书(cameron hughes,tracey hughes 的多核编程)。
到目前为止,我还没有让他们的任何程序运行他们的书说它应该在 99% 的计算机上运行,所以我有点困惑,但在他们书中每个程序的末尾,他们都有“编译和链接指令”......我需要输入吗?它看起来像这样“C++ -oguess_itguess_it.cc”。我现在运行的代码是:
#include <iostream>
#include <windows.h>
#include <string>
#include <spawn.h>
#include <sys/wait.h>
using namespace std;
int main(int argc,char *argv[],char *envp[])
{
pid_t ChildProcess;
pid_t ChildProcess2;
int RetCode1;
int RetCode2;
int Value;
RetCode1 = posix_spawn(&ChildProcess,"find_code",NULL,
NULL,argv,envp);
RetCode2 = posix_spawn(&ChildProcess2,"find_code",NULL,
NULL,argv,envp);
wait(&Value);
wait(&Value);
return(0);
}
我正在运行 Windows 7(32 位),AMD athion x2 7550 双核处理器,VC++ 2008 Express 版。
我收到以下错误: fatal error C1083:无法打开包含文件:'spawn.h':没有这样的文件或目录
任何人都知道为什么我不能让我的代码运行?我需要下载一些东西吗?因为我读了这本书,没有看到任何关于下载任何东西的信息,但我可能是错的。 :(
最佳答案
看起来那本书正在使用 POSIX 线程。 Visual Studio 默认使用 Windows 线程,它具有完全不同的 API。
您很可能只需要获取 POSIX Thread library for Windows 的副本.这将包括 spawn.h
和适当的 lib 文件供您使用。
关于multithreading - 无法从编程书上运行我的代码(c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2421836/