Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake : <pthread.h> not found in Windows

I'm newbie with CMake. I tested it on Linux for a program I am making. This program uses (POSIX Threads lib), so in my CMakeList, I added :

find_package(Threads)

It works on Linux distribs (Arch, Mint, Ubuntu, ...), but now, I'm trying it in Windows32 (Visual Studio 9 2008), and I get this message during generation :

-- Looking for include file pthread.h - not found

(and when I compile output project file, pthread.h is indeed not found).

On Windows, considering "C:\pthread" as my pthread directory, I defined in path :

  • "C:\pthread\include" (where resides the famous "pthread.h")
  • "C:\pthread\" (in the case where CMake looks for an "include" somewhere)

But I still get the same error (even after deleted cache). I know I could "manually" add Pthread in my Project, or define some constants in CMakeList.txt, but I thinks it's not the principle of CMake : I could use the SAME "CMakeList.txt" on all systems, right ? So how can I tell to CMake "Hey ! Looks here ! Pthread is in this directory !". Maybe Cmake doesn't look in PATH, but in another environment variable, but I didn't find this information.

Thank you for reading.

EDIT : I don't know if it makes a difference, but my project is a C++ project (not C)

like image 727
Neozaru Avatar asked Nov 04 '12 12:11

Neozaru


People also ask

Does pthread work on Windows?

Windows does not support the pthreads standard natively, therefore the Pthreads4w project seeks to provide a portable and open-source wrapper implementation. It can also be used to port Unix software (which uses pthreads) with little or no modification to the Windows platform.

What is pthread H?

The pthread. h header file contains function declarations and mappings for threading interfaces and defines a number of constants used by those functions. The header includes the sched. h header.


2 Answers

What I did, I edited the cmake file:

option(CMAKE_USE_WIN32_THREADS_INIT "using WIN32 threads" ON)

and

option(gtest_disable_pthreads "Disable uses of pthreads in gtest." ON)

(I am using google test)

like image 51
radato Avatar answered Sep 19 '22 19:09

radato


As far as i know, Pthreads is not natively supported on windows platform. Unless you use some thing like

win services for unix

Windows only has win32 threads.

However, this is a project which provides pthreads on windows

pthreads on win32

like image 37
fkl Avatar answered Sep 18 '22 19:09

fkl