Abhishek Sagar Abhishek Sagar - 1 year ago 210
C++ Question

error: ‘pthread’ does not name a type

i am trying compiling my project but seeing the following error.

code : RESTServer.h

#ifndef __RESTSERVER__
#define __RESTSERVER__

#include <string>
#include <pthread.h>

using namespace std;

class RESTServer{
static pthread *thread;
static void init_rest_server();

Error :

RESTServer.h:14:10: error: ‘pthread’ does not name a type
static pthread *thread;

I am trying to declare a pointer to pthread as a member of C++ class. Can anyone pls help me here.

Answer Source

Read pthread_create(3); the opaque type is pthread_t (not pthread*) for thread handle.

BTW, hoping that you use some good C++11 -or C++14- implementation (e.g. GCC 5 or GCC 6 on Linux) you should consider using C++11 threads library, i.e. std::thread.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download