我无法在窗口平台中使用 pthread [英] I can't use pthread in window platform
问题描述
我的环境是 Windows8.1(64 位)并使用 Visual Studio 2010.
My env is Windows8.1 (64bit) and using Visual Studio 2010.
我确实把所有 *.dll 文件放在 system32 、SYSWOW64 中(因为我使用的是 win8 64 位.)
I did put all *.dll files in system32 , SYSWOW64(because I use win8 64bit.)
和链接位置,用于 x64 系统和 VC 2010 的 *.lib 文件.
and link location where *.lib file for x64-system with VC 2010.
当然,我添加了额外的文件夹 lib forders.. ,包括文件夹.. 等..
of course, I add additional folder lib forders.. , include folders.. etc..
但是当我尝试编译pthread-used"项目时,发生了致命错误.
but when I try compile "pthread-used" project, fatal error has occur.
-来源
#include<pthread.h>
#include<stdio.h>
int doit_id,trd_id;
pthread_t trd;
void *doit(void *data){
doit_id = (int)data;
return 0;
}
int main(){
trd_id=pthread_create(&trd,NULL,doit,0);
return (0);
}
-错误
1.obj : error LNK2019: unresolved external symbol __imp__pthread_create (referenced in function _main)
C:\Users\~program Location~ : fatal error LNK1120: 1 unresolved externals
请帮帮我
推荐答案
您的 main()
正在寻找名称 __imp__pthread_create
的事实表明您正在构建您的 32 位目标项目.
The fact that your main()
is looking for the name __imp__pthread_create
indicates that you're building your project for a 32-bit target.
64 位 Win32 pthread 库具有 pthread_create()
的导入符号,名称为:
The 64-bit Win32 pthread library has a import symbol for pthread_create()
with the name:
__imp_pthread_create
32 位 Win32 pthread 库具有:
The 32-bit Win32 pthread libary has:
__imp__pthread_create
注意 32 位库中的额外下划线 - 它与您的 main()
正在寻找的名称约定相匹配,因此这表明您正在为 32 位目标构建.额外的下划线是 x86 构建如何在 Win32 pthread 库使用的 cdecl 调用约定中处理名称的一部分.x64 不使用 cdecl 调用约定(x64 只有一个调用约定)并且下划线不在 x64 构建中的符号前面.
Note the extra underscore in the 32-bit lib - that matches the name convention that your main()
is looking for, so it's an indication that you're building for a 32-bit target. The extra underscore is part of how x86 builds treat names in the cdecl calling convention used by the Win32 pthread library. x64 doesn't use a cdecl calling convention (x64 has only a single calling convention) and underscores are not prepended to symbols in x64 builds.
我认为您需要下载或构建 32 位 pthread 库,或者更改您的项目配置以构建 64 位目标.
I think you need to either download or build the 32-bit pthread library or change your project configuration to build for a 64-bit target.
这篇关于我无法在窗口平台中使用 pthread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!