2014-10-10 63 views
0

我在Borland C++ 5.02编程C++。我试图运行此代码:borland多线程

#include <stdio.h> 
#include <pthread.h> 

#define NUM 5 

main() 
{ 
    pthread_t t1, t2; /* two threads */ 

    void *print_msg(void *); 

    pthread_create(&t1, NULL, print_msg, (void *)"hello"); 
    pthread_create(&t2, NULL, print_msg, (void *)"world\n"); 
    pthread_join(t1, NULL); 
    pthread_join(t2, NULL); 
} 

但我得到这个错误:

信息:编译C:\ BC5 \ BIN \ noname00.cpp

错误:noname00.cpp( 2,2):无法打开包含文件 'PTHREAD.H'

错误:noname00.cpp(8,15):未定义符号 '的pthread_t'

错误:noname00.cpp(8 ,15):缺少陈述;

错误:noname00.cpp(12,18):调用未定义函数 '在pthread_create'

我强调这是由'PTHREAD.H'引起的主要误差。 我检查了此文件的包含文件夹。它不存在。我该如何解决这个问题?

+1

你坚持认为需要使用Borland C++ 5的产品吗?为什么还会用C++ 98标准之前的17年前发布的产品来构建任何东西? – dasblinkenlight 2014-10-10 13:17:45

+0

学校应该停止使用Turbo和Borland C++。 – 2014-10-11 08:18:47

回答

1

Borland的C++工具链不包含pthreads库,也没有Windows SDK。您将需要使用本机Win32线程API或获得Windows的第三方pthreads实现。

一些选项包括:

我不知道这些东西有多好与用Borland C++工作5.x的

另一种方法是使用工具链包括并行线程的实现,如TDM的MinGW的工具链:

0

你的问题是#include <pthread.h>

  • 你需要可以复制所有的并行线程相关的文件(.H, .C,的.cpp, .HPP,的.lib, .OBJ)
  • 纳入编译器包含文件夹
  • 或在您的项目/编译器设置中添加include路径
  • 或将其复制到您的项目并更改为#include <pthread.h>#include "pthread.h"

所以编译器没有找到pthread.h头

  • 所以没有从它的数据类型是由编译器的一侧(像的pthread_t)称为
  • 因此错误的休息..