How to add pthread library to C++ project in Visual Studio Community Edition?

35,026

Did you forget to add the .dll file to the bin folder?

If you follow his tutorial exactly, you won't need to add any .lib files in Additional Dependencies (note steps 6-10 in his tutorial). I followed his tutorial and got it to work. I'm using Visual Studio 12.0 Ultimate, but it should be the same or a very similar process for your version of Visual Studio.

I actually followed his tutorial here: http://web.cs.du.edu/~sturtevant/w13-sys/InstallingpthreadsforVisualStudio.pdf where he provides you a compressed folder containing the files you need. I got the files from there.

Here's his tutorial again:

Add the 3 .h files (pthread.h, sched.h, sempahore.h) to the include folder under \VC (mine is C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC). Add the pthreadVC2.lib to the lib folder and pthreadVC2.dll file to the bin folder.

Next, open the property manager: in Visual Studio, go to View>Other Windows>Property Manager. Expand the Debug folder. Open Microsoft.Cpp.Win32.user (or a similarly named Property Sheet). Go to Common Properties>Linker>Input. In Additional Dependencies add pthreadVC2.lib as a dependency.

Share:
35,026
James Joshua Street
Author by

James Joshua Street

Updated on July 18, 2020

Comments

  • James Joshua Street
    James Joshua Street almost 4 years

    I wanted to be able to use pthreads in visual studio because I was using it to debug, and was following the tutorial here.

    http://web.cs.du.edu/~sturtevant/pthread.html

    It seems simple enough, add the .h files to the C++ include directory and add the .lib file to the lib directory.

    However, while the .h files are being detected, I am getting an error:

    Error   1   error LNK2019: unresolved external symbol __imp__pthread_create 
    

    I take this to mean that the .lib file is not being detected properly.

    I thought I could just add the .lib file to the lib listing at Project Properties -> Linker -> Additional Dependencies using its full path like so:

    D:\Visual Studio\VC\lib\pthreadVC2.lib;kernel32.lib;user32.lib;
    

    Not sure if there is any advantage to appending the new lib to the beginning of the list or the end of the list, but neither seems to work.

    In the command line tab, we can see the command that is actually run (I think):

    /OUT:"C:\projects\GTKWavePipe\NamedPipeTest\Debug\NamedPipeTest.exe" /MANIFEST /NXCOMPAT /PDB:"C:\projects\GTKWavePipe\NamedPipeTest\Debug\NamedPipeTest.pdb" /DYNAMICBASE "D:\Visual Studio\VC\lib\pthreadVC2.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"C:\projects\GTKWavePipe\NamedPipeTest\Debug\NamedPipeTest.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\NamedPipeTest.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 
    

    Does anyone know what I might be doing wrong? Ultimately I can always just go do my debugging in my cygwin environment, but the debugger I'm using there is not as good.

    Plus, I think being able to add libraries into visual studio seems like a useful skill.

  • Seabass77
    Seabass77 about 5 years
    For people using the community edition I found my path here: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib[x86 or x64] Check your configuration to see which folder you want to place your .lib in . As for the .dll you can just have it in a folder that is in your %PATH% (environmental variables)