2

I download pthread-w32-2-9-1-release.zip, unzip it and use Prebuild/include lib and dll with VisualStudio2013.

I set up a VC++ empty project "helloc" with main.c, then write a simple example with pthread_create pthread_join functions.

This is my configure:

Properties->C/C++->General->Additional Include Directories, add "F:\pthread_win32\include"

Properties->Linker->General->Additional Library Directories, add "F:\pthread_win32\lib\x86"

Properties->Linker->Input->Additional Dependencies, add "pthreadVC2.lib"

And it's successfully build, but when I click "Local Windows Debugger", the console break with "helloc.exe error because cannot find pthreadVC2.dll".

Then I copied pthreadVC2.dll to helloc/Debug/, same directory with helloc.exe, finally it's working.

But I don't know why the pthreadVC2.lib and pthreadVC2.dll are both required by helloc.exe. Is it a must that both lib and dll being used in VisualStudio ?

If only one of them (pthreadVC2.lib pthreadVC2.dll) is enough to support helloc.exe, how can I specify which one (dll or lib) I want to use in VisualStudio with helloc.exe ?

And I don't want to put all pthread libs and dlls into "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC", I want to know how to configure manually.

linrongbin
  • 2,967
  • 6
  • 31
  • 59

1 Answers1

1

AFAICT, the pre-built library is just an import library for the DLL. (Allowing you to link against the DLL, hence required) If you want to link statically, you'll have to rebuild the library yourself. See the README file for more information.

Hasturkun
  • 35,395
  • 6
  • 71
  • 104
  • So I guess it is a MUST to use both lib and dll in one Project. Right ? – linrongbin Oct 13 '15 at 14:43
  • To use the DLL, you either need to link against the import library (LIB file), or use `LoadLibrary()` and `GetProcAddress()` at run time to load the DLL and use its exports. You can link statically against the library (and not use the DLL), provided you build it yourself first (which will give you a static link library, also .LIB IIRC) – Hasturkun Oct 13 '15 at 15:43