1

Student programmer here. I write C++ code in a Windows text editor and compile it with g++. I've been given code to compile which has #include <pthreads.h>. When I try to compile it with PowerShell, I get pthread.h: No such file or directory.

A little research informs me that pthreads is a part of Linux, not Windows, but there's a 3rd party Pthreads for Windows which is well-regarded. But I can't figure out how to install it. It includes some instructions for building it, but that's not what I need.

I tried the instructions in this question. I downloaded the pre-built version of pthreads, put the .dlls in my PATH variable, and created LIB and INCLUDE variables (there weren't any to begin with) and pointed them at the .lib and .h files, respectively. But I get the same error when trying to compile my code.

Grinnioc
  • 21
  • 2
  • I'd suspect for the windows version it's the best to compiole it from scratch. But doesn't your GCC version support the c++-11 standard? It should come with the `std::thread` implementation, and should work on Windows OS as well. Is there any specific reason, why you would need to use the pthread API directly? – πάντα ῥεῖ Sep 14 '20 at 19:42
  • ***No such file or directory*** did you try to debug this. Did you add the include path for g++ to find where you put pthread.h? – drescherjm Sep 14 '20 at 19:42
  • You say `g++` but which complete build system (and version) have you installed ? – Richard Critten Sep 14 '20 at 19:44
  • 1
    How wedded to pthreads are you? Is [`std::thread`](https://en.cppreference.com/w/cpp/thread/thread) a viable alternative? – user4581301 Sep 14 '20 at 19:50
  • Probably _not_ related... on Linux (I use lubuntu 20.04), there exists a , but I have _never_ (knowingly) used it, even for my thread code. HOWEVER, when my code uses std::thread, i must link in some sort of thread library using "-pthread" (not -lpthread), else I get several undefined symbols. If code has "#include " my link requires "-pthread". – 2785528 Sep 15 '20 at 01:29

2 Answers2

1

Based on some of the comments, I started making sure everything was up-to-date. This led me to a solution:

  1. Used cygwin updater to install everything in the cygwin "devel" category.
  2. Built the application from the cygwin console.
Grinnioc
  • 21
  • 2
0

Try calling g++ -IC:\the\directory\where\you\have\the\header\file.