Hello I want to use pthreads in Visual C++, VS2012. I downloaded the release file but I don't know how to include and load it for VS2012, as it gives such error IntelliSense: cannot open source file "pthread.h"
-
Like any compiler, it has to know where your include files reside. You set that in the project properties.– Carey GregoryNov 30, 2012 at 1:00
-
You know vs2012 supports the C++11 standard thread library, right? Just checking.– Benjamin LindleyNov 30, 2012 at 1:11
3 Answers
Right click on project -> properties -> C/C++ -> General -> Additional include directories.
Add the directory there.
For the libraries, go to Linker -> General and add the directory with the libs, then go to Linker -> Input and add the libraries themselves.
Also, note that IntelliSense isn't a compiler, so that might even be a false positive error.
-
Still it does not work: sourceware.org/pub/pthreads-win32/… I downloaded this and I am including Pre-built.2/dll/x86 folder to those places and added dll names to input part. Nov 30, 2012 at 1:14
-
@SarpKaya "doesn't work" without an error message is the most useless feedback you can give. Nov 30, 2012 at 1:15
-
the same error as I posted "IntelliSense: cannot open source file "pthread.h"" Nov 30, 2012 at 1:16
-
@SarpKaya I find screenshots of the property pages most helpful in remotely troubleshooting these types of situations. Nov 30, 2012 at 1:17
-
@SarpKaya as mentioned before, Intellisense is not a compiler. Have you tried actually compiling the code? Nov 30, 2012 at 1:18
Right click on the project and select the property pages. Then add path to the includes and the library to VC++ Directories. In the linker section, add the lib file name itself (likely pthreads.lib).
-
I'd advise against modifying the VC++ directories for this. There are better options available. Nov 30, 2012 at 1:10
-
There is no difference between changing the additional include directories and the VC++ directories really. Nov 30, 2012 at 1:17
There is a difference between "Additional Include Directories" and "VC++ Directories":
Additional Include Directories is encapsulated within the Project File. So making changes here does not break or modify the compilation or linking of any other project you work on.
VC++ Directories is shared by all projects you build with that compiler. You can easily break other projects by modifying what you find here.
To avoid breaking (sometimes in very subtle and confusing ways) unrelated projects, it is preferable to encapsulate your directory settings within a particular project by setting Additional Include Directories (and equivalent for libs).