about pthread.h
-
i use in linux by make, but it output: Linking CppFit_tests lib/libCppFit.a(Mutex.o): In function `Mutex::Mutex()': Mutex.cpp:(.text+0x18): undefined reference to `pthread_mutexattr_init' Mutex.cpp:(.text+0x2b): undefined reference to `pthread_mutexattr_settype' lib/libCppFit.a(Mutex.o): In function `Mutex::Mutex()': Mutex.cpp:(.text+0xaa): undefined reference to `pthread_mutexattr_init' Mutex.cpp:(.text+0xbd): undefined reference to `pthread_mutexattr_settype' lib/libCppFit.a(Thread.o): In function `Thread::start()': Thread.cpp:(.text+0x230): undefined reference to `pthread_create' lib/libCppFit.a(Thread.o): In function `Thread::join()': Thread.cpp:(.text+0x268): undefined reference to `pthread_join' collect2: ld returned 1 exit status The program is: struct MutexInnards { public: pthread_mutex_t mutex; int nestLevel; }; Mutex::Mutex() { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); innards = new MutexInnards(); innards->nestLevel = 0; pthread_mutex_init(&innards->mutex, &attr); } Mutex::~Mutex() { pthread_mutex_destroy(&innards->mutex); delete innards; } void Mutex::acquire() { pthread_mutex_lock(&innards->mutex); // innards->nestLevel++; } void Mutex::release() { // innards->nestLevel--; // if (innards->nestLevel <= 0) // { // innards->nestLevel = 0; pthread_mutex_unlock(&innards->mutex); // } }
-
i use in linux by make, but it output: Linking CppFit_tests lib/libCppFit.a(Mutex.o): In function `Mutex::Mutex()': Mutex.cpp:(.text+0x18): undefined reference to `pthread_mutexattr_init' Mutex.cpp:(.text+0x2b): undefined reference to `pthread_mutexattr_settype' lib/libCppFit.a(Mutex.o): In function `Mutex::Mutex()': Mutex.cpp:(.text+0xaa): undefined reference to `pthread_mutexattr_init' Mutex.cpp:(.text+0xbd): undefined reference to `pthread_mutexattr_settype' lib/libCppFit.a(Thread.o): In function `Thread::start()': Thread.cpp:(.text+0x230): undefined reference to `pthread_create' lib/libCppFit.a(Thread.o): In function `Thread::join()': Thread.cpp:(.text+0x268): undefined reference to `pthread_join' collect2: ld returned 1 exit status The program is: struct MutexInnards { public: pthread_mutex_t mutex; int nestLevel; }; Mutex::Mutex() { pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); innards = new MutexInnards(); innards->nestLevel = 0; pthread_mutex_init(&innards->mutex, &attr); } Mutex::~Mutex() { pthread_mutex_destroy(&innards->mutex); delete innards; } void Mutex::acquire() { pthread_mutex_lock(&innards->mutex); // innards->nestLevel++; } void Mutex::release() { // innards->nestLevel--; // if (innards->nestLevel <= 0) // { // innards->nestLevel = 0; pthread_mutex_unlock(&innards->mutex); // } }
I don't really see much of a question here but I assume the problem is the undefined references in your link action, all of which suggest you are missing a reference to a library from your make file.
Just say 'NO' to evaluated arguments for diadic functions! Ash
-
I don't really see much of a question here but I assume the problem is the undefined references in your link action, all of which suggest you are missing a reference to a library from your make file.
Just say 'NO' to evaluated arguments for diadic functions! Ash
thanks, i will look something about make file again
-
thanks, i will look something about make file again
It's not so much the make file itself but your rules. In your code you have calls to
pthread_mutexattr_init
and others, but the linker cannot resolve those names. This suggests that the names are defined in an external library which has not been added to your list of dependencies in the build of your executable. Identify that library and you have solved the issue.Just say 'NO' to evaluated arguments for diadic functions! Ash
-
It's not so much the make file itself but your rules. In your code you have calls to
pthread_mutexattr_init
and others, but the linker cannot resolve those names. This suggests that the names are defined in an external library which has not been added to your list of dependencies in the build of your executable. Identify that library and you have solved the issue.Just say 'NO' to evaluated arguments for diadic functions! Ash
thanks for your help
-
thanks for your help