I have written the following T
class with pthread
. When i compile this class using g++ -lpthread then it's working fine. But if i extend this class from another class A
and compile all together it's returns an error; "undefined reference to pthread_cancel"
Code:
class T{
private:
pthread_t thread;
public:
void start(){
pthread_create(&thread,NULL,&run,this);
}
void destroy_thread(){
pthread_cancel(thread);
}
static void* run(void*){}
~Thread(){
destroy_thread();
}
};
Next class:
class A:T{
A(){
start();
}
}
Main
int main(){
A a;
return 0;
}
Compile:
g++ -c T.cpp A.cpp Main.cpp -lpthread
g++ -o out *.o
Error: undefined reference to `pthread_cancel'
#include <pthread.h>
line somewhere? – rodrigo