开发者

How do I install pthread_win32 (Windows pthread / posix thread library) for Visual Studio 2005?

Just to be clear - I have searched the depths of the internet and back for information on how to do this

I'm looking for assistance setting up pthread_Win32 to work with Visual Studio 2005. I'm programming in C, and I have a number of multithreaded assignments to write using pthread.h. However, since pthread is native to unix, I have to write all of my code, ftp it, and then ssh to my class' remote unix system to run it. It makes development take so much longer, and it's incredibly inefficient. I'd love (more than anything) to be able to get this working on my win32 machine, so I can develop in visual studio as I've been doing for quite some time.

I've installed the pthread.lib file and pthread.h file into the respective lib/header directories, where all of the other files are. The DLL on the other hand (the actual library), I've placed in c:\windows\system32. I've tried to add the DLL as a dependency (right click project -> references -> Add new reference), but as开发者_如何学Python others have stated, all I get is a blank dialogue box with no option to add any DLL files or anything. It seems to recognize the header file, but I get these errors when I compile:

1>Linking...

1>main.obj : error LNK2019: unresolved external symbol _imp_pthread_join referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol _imp_pthread_create referenced in function _main

1>main.obj : error LNK2019: unresolved external symbol _imp_pthread_exit referenced in function _fcount

From my research, I've determined that this is a problem with the DLL, and I'm assuming it can't find the definitions of the functions I've referenced in my code. I've searched high and low and I can't seem to figure out any way to overcome this problem. I've added the directories of the lib/header files to my linker, just in-case, but that didn't solve the issue. I need to do something, in visual studio, to specify that I need pthreadVC2.dll as a project dependency - and it seems to be impossible (and extremely frustrating) at this point.

Any words of wisdom?

Thank you very much


I have been through this problem recently. It appears that the __imp__ prefix is prepended to the function name in case pthread.h is included in dynamic linking mode. Simply add the PTW32_STATIC_LIB define to your project or your source code before including pthread.h should solve the issue.

#define PTW32_STATIC_LIB
#include <pthread.h>

Although, I am not completely over as Visual Studio now trys to link with the _[FuncName] instead of [FuncName]

In visual studio, function seems to be declared differently wether you are going to link them statically (.lib) or dynamically (.dll).

To define a function you will link dynamically :

__declspec (dllimport) int myFunc(int myArgs) ;

To define function you are exporting for dynamic linking :

__declspec (dllexport) int myFunc(int myArgs) ;

And the simpliest, to define a function you will link statically:

int myFunc(int myArgs) ;

[EDIT]

I am going on my investigations and went through this on MS help center. It seems that to avoid the _[FuncName] effect it is required to define a static linked library function by the following:

int __cdecl myFunc(int MyArgs) ;


Have you added pthreadVC.lib (or whichever particular lib you need) to the project property:

Linker/Input/Additional Dependencies

It's not enough to just have the lib file in a particular directory, the linker needs to be told to use it as an input.


Just adding pthreadVC2.lib to linker list is not suffiecient. You also have to add addtional lib like pthreadVCE2.lib and pthreadVSE2.lib.

I am facing same issue but then I resolved it through adding these files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜