I can't use pthread in window platform

ぃ、小莉子 提交于 2020-01-01 07:06:13

问题


My env is Windows8.1 (64bit) and using Visual Studio 2010.

I did put all *.dll files in system32 , SYSWOW64(because I use win8 64bit.)

and link location where *.lib file for x64-system with VC 2010.

of course, I add additional folder lib forders.. , include folders.. etc..

but when I try compile "pthread-used" project, fatal error has occur.

-source

#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);
}

-error

1.obj : error LNK2019: unresolved external symbol __imp__pthread_create (referenced in function _main)
C:\Users\~program Location~ : fatal error LNK1120: 1 unresolved externals

please,help me


回答1:


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.

The 64-bit Win32 pthread library has a import symbol for pthread_create() with the name:

__imp_pthread_create

The 32-bit Win32 pthread libary has:

__imp__pthread_create

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.

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.



来源:https://stackoverflow.com/questions/20020264/i-cant-use-pthread-in-window-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!