Multithreading borland中的多线程 我在Borland C++ 5.02中编程C++。我正在尝试运行以下代码: #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); } #包括 #包括 #定义NUM 5 main() { pthread_t t1,t2;/*两个线程*/ 作废*打印信息(作废*); 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); }

Multithreading borland中的多线程 我在Borland C++ 5.02中编程C++。我正在尝试运行以下代码: #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); } #包括 #包括 #定义NUM 5 main() { pthread_t t1,t2;/*两个线程*/ 作废*打印信息(作废*); 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); },multithreading,include,pthreads,header-files,borland-c++,Multithreading,Include,Pthreads,Header Files,Borland C++,但我得到了这个错误: 信息:正在编译C:\BC5\BIN\noname00.cpp 错误:noname00.cpp(2,2):无法打开包含文件“PTHREAD.H” 错误:noname00.cpp(8,15):未定义符号“pthread\u t” 错误:noname00.cpp(8,15):语句丢失 错误:noname00.cpp(12,18):调用未定义的函数“pthread_create” 我突出显示了由'PTHREAD.H'引起的主要错误。我检查了这个文件的include文件夹。它不存在。

但我得到了这个错误:

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

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

错误:noname00.cpp(8,15):未定义符号“pthread\u t”

错误:noname00.cpp(8,15):语句丢失

错误:noname00.cpp(12,18):调用未定义的函数“pthread_create”

我突出显示了由
'PTHREAD.H'
引起的主要错误。我检查了这个文件的include文件夹。它不存在。如何解决此问题?

您的问题是
\include

  • 您需要复制所有与pthread相关的文件(.h、.c、.cpp、.hpp、.lib、.obj)
  • 放入编译器包含文件夹
  • 或者在项目/编译器设置中添加包含路径
  • 或者将其本地复制到您的项目中,并将
    #include
    更改为
    #include“pthread.h”
所以编译器没有找到pthread.h头

  • 因此,编译器端不知道其中的数据类型(如pthread\u t)
  • 因此,其余的错误

Borland的C++工具链不包括p螺纹库,也不包括Windows SDK。您需要使用本机Win32线程API,或者为Windows获取第三方pthreads实现

一些选择包括:

  • winpthreads.h:
  • pthreads-win32:
我不知道这些东西与Borland C++ 5有多好。X.< 另一种选择是使用包含pthreads实现的工具链,如TDM的MinGW工具链:


是否维护一个需要使用Borland C++ 5的产品?为什么人们会用17年前发布的产品来处理任何东西,在C++ 98标准之前的整整一年?学校应该真正停止使用Turbo和Borland C++。