Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. about pthread.h

about pthread.h

Scheduled Pinned Locked Moved ATL / WTL / STL
c++linuxannouncement
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lxlenovostar
    wrote on last edited by
    #1

    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); // } }

    L 1 Reply Last reply
    0
    • L lxlenovostar

      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); // } }

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      L 1 Reply Last reply
      0
      • L Lost User

        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

        L Offline
        L Offline
        lxlenovostar
        wrote on last edited by
        #3

        thanks, i will look something about make file again

        L 1 Reply Last reply
        0
        • L lxlenovostar

          thanks, i will look something about make file again

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • L Lost User

            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

            L Offline
            L Offline
            lxlenovostar
            wrote on last edited by
            #5

            thanks for your help

            L 1 Reply Last reply
            0
            • L lxlenovostar

              thanks for your help

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You're welcome. :thumbsup:

              Just say 'NO' to evaluated arguments for diadic functions! Ash

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups