C++ 代码::块pthread示例无法编译
也许这个问题很简单,但我不知道如何解决: 我尝试编译一个示例,它在Windows7(64位)上有C++ 代码::块pthread示例无法编译,c++,compiler-errors,pthreads,codeblocks,C++,Compiler Errors,Pthreads,Codeblocks,也许这个问题很简单,但我不知道如何解决: 我尝试编译一个示例,它在Windows7(64位)上有pthreas,带有代码块,我下载了预编译库并设置了building\u选项:编译器pthreadLib\include的路径和pthreadLib\lib\x64 该计划是: extern "C" { #include <pthread.h> #include <unistd.h> } #include <iostream> #include
pthreas
,带有代码块,我下载了预编译库并设置了building\u选项:编译器pthreadLib\include
的路径和pthreadLib\lib\x64
该计划是:
extern "C"
{
#include <pthread.h>
#include <unistd.h>
}
#include <iostream>
#include <windows.h>
using namespace std ;
void * function1(void * argument);
void * function2(void * argument);
int main( void )
{
pthread_t t1, t2 ; // declare 2 threads.
pthread_create( &t1, NULL, function1,NULL); // create a thread running function1
pthread_create( &t2, NULL, function2,NULL); // create a thread running function2
Sleep(1);
return 0;
}
void * function1(void * argument)
{
cout << " hello " << endl ;
Sleep(2); // fall alseep here for 2 seconds...
return 0;
}
void * function2(void * argument)
{
cout << " world " << endl ;
return 0;
}
我必须在
C::B
中进行其他设置吗?我尝试添加链接器命令-lpthread
,但没有被识别。两天后,我找到了它
第一:我安装了Windows操作系统的。
下一步:我将C::B
设置为在此之后使用minGW_64
。
此外:我添加到链接器libs。\libs\Pre-build.2\lib\x64\libpthreadGC2.a
和。\libs\Pre-build.2\lib\x64\pthreadVC2.lib
。最后,我在我的项目中添加了pthreadGC2.dll
(64位版本!)
吸取的教训是,不要混用lib。用于Linux的86和64编译器。
用睡眠(1)代替睡眠(1)看,我看了那篇文章。在错误消息中:
mingw32-g++.exe-o bin\Release\RIP.exe obj\Release\main.o-s libpthreadGC2.a pthreadVC2.lib
2当我给出路径时,会自动链接lib。提到当我手动将-lpthread
包含在C::B
中时,无法识别-lpthread
,您可以详细说明吗?错误是未定义对\u imp\u pthread\u create',它与睡眠无关。。。
mingw32-g++.exe -L..\libs\Pre-built.2\lib\x64 -LD:\DropBox\WorkUT\Programs\MyODP\libs -o bin\Release\RIP.exe obj\Release\main.o -s ..\libs\Pre-built.2\lib\x64\libpthreadGC2.a ..\libs\Pre-built.2\lib\x64\pthreadVC2.lib
obj\Release\main.o:main.cpp:(.text.startup+0x36): undefined reference to `_imp__pthread_create'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 1 warning(s) (0 minute(s), 0 second(s))