I have the following test program.
#include <iostream>
#include <cstdlib>
using namespace std;
pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
int main(int argc, char *argv[])
{
int iret;
iret = pthread_mutex_trylock( & mymutex );
cout << "Test2 !!! " << endl;
pthread_mutex_unlock( & mymutex );
return EXIT_SUCCESS;
}
If I compile it without adding the pthread library I get the error for unresolved error for pthread_mutex_trylock , but only for function pthread_mutex_trylock.
If I replace pthread_mutex_trylock with pthread_mutex_trylock the program is compiled and runnig well also without the -lpthread* option.
If I add the -lpthraed option to the compile commands all runs well this run well : $ g++ test2.c -o test2 -lpthread this warn unresolved : $ g++ test2.c -o test2
Example error output:
$ g++ test2.c -o test2
/tmp/ccU1bBdU.o: In function main':
test2.c:(.text+0x11): undefined reference to
pthread_mutex_trylock'
collect2: ld returned 1 exit status
If I replace the instruction iret = pthread_mutex_trylock( & mymutex );
with iret = pthread_mutex_lock( & mymutex ); the program compiles and run without error also if didn't add the pthread libarry to the compile command I know that is right to have the unresolved error if I didn't use the -lpthread option , but why I have not the same unresolved error also for other pthread_ function ?
I'm using gcc 4.4.2 on fedora 12
$ g++ --version
g++ (GCC) 4.4.2 20091222 (Red Hat 4.4.2-20)
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Do some have some suggestion about the meaning of this unreference only for pthread_mutex_trylock ?
thanks for the help, Enzo