undefined reference to `_p_mutex_lock'

This is a discussion on undefined reference to `_p_mutex_lock' within the Windows Programming forums, part of the Platform Specific Boards category; First, I am noob at threads. I am modifying a program that runs on a windows server platform to use ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    15

    undefined reference to `_p_mutex_lock'

    First, I am noob at threads. I am modifying a program that runs on a windows server platform to use two parallel threads and mutex locks on global resources. I compile with cygwin's gcc compiler
    gcc source.c -o out.exe -lcurl (the program also uses curl)
    The error it gives me:
    /cygdrive/c/DOCUME~1/ADMINI~1/LOCALS~1/Temp/ccr8d7lT.o:myevault.2.1.0.c.text+0
    x9e03): undefined reference to `_p_mutex_lock'
    collect2: ld returned 1 exit status
    NOTE: adding -lpthread to the gcc command does no good

    Here are the (I think) relevant pthread and mutex sections from the program:
    =============================================
    Code:
    #include <string.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    #include <windows.h>
    #include <winbase.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <dirent.h>
    #include <curl/curl.h>
    #include <pthread.h>
    #include <unistd.h>
     
    /*  also in the global definitions */
    pthread_mutex_t CheckLogMutex = PTHREAD_MUTEX_INITIALIZER; 
    pthread_mutex_t set_state_and_ftpMutex = PTHREAD_MUTEX_INITIALIZER; 
     
    //function one
    static void *one(void *vptr_args)
    {
        // function code
        //.
        //.
        //.
        pthread_mutex_lock( &set_state_and_ftpMutex );
             //global resource code
        pthread_mutex_unlock( &set_state_and_ftpMutex  );
        return NULL;
    }
    //function two
    static void *two(void *vptr_args)
    {
        // function code
        //.
        //.
        //.
        pthread_mutex_lock( &set_state_and_ftpMutex );
             //global resource code
        pthread_mutex_unlock( &set_state_and_ftpMutex  );
        return NULL;
    }
    main
    {
      pthread_t thread_do_one;
      pthread_t thread_do_two;
      //code  
      //...
            if (pthread_create(&thread_do_one, NULL, one, NULL) != 0)
            {
              //handle thread creation error
            }
            if (pthread_create(&thread_do_two, NULL, two, NULL) != 0)
            {
              //handle thread creation error
            }
     
      pthread_join(one, NULL);
      //code...
    }
    ================================================== ===


    So I figure I am missing a some library file or something, BUT I wanted to see if a simple example would work. From a tutorial on threads, I created a simple "threads with mutex" test program. It compiles and runs fine. (compiled with gcc source.c -o out.exe)

    /* this program compiles and runs fine */
    Code:
    #include <stdio.h>
    #include <pthread.h>
     
    pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
     
    int count = 0;
     
    void* function1( void* arg )
    {
        int tmp = 0;
     
        while( 1 ) {
            pthread_mutex_lock( &mymutex );
            tmp = count++;
            pthread_mutex_unlock( &mymutex );
            printf( "Count is %d\n", tmp );
     
            /* snooze for 1 second */
            sleep( 1 );
        }
     
        return 0;
    }
     
    void* function2( void* arg )
    {
        int tmp = 0;
     
        while( 1 ) {
            pthread_mutex_lock( &mymutex );
            tmp = count--;
            pthread_mutex_unlock( &mymutex );
            printf( "** Count is %d\n", tmp );
     
            /* snooze for 2 seconds */
            sleep( 2 );
        }
     
        return 0;
    }
     
    int main( void )
    {
      pthread_t one;
      pthread_t two;
    
        pthread_create( &one, NULL, &function1, NULL );
        pthread_create( &two, NULL, &function2, NULL );
     
        /* Let the threads run for 60 seconds. */
        sleep( 60 );
     
        return 0;
    }
    At this point, I don't have any ideas. Any help will be MUCH appreciated.

    Leon

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    Is myevault.c the name of one of your own source files?

    If you compile with "-g" the linker message will include the actual line number which is causing the problem.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    15
    THANKS! It was a simple stupid typo!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21