-nodefaultlibs and pthreads

Rich Felker dalias at aerifal.cx
Fri Jun 30 14:22:58 UTC 2006


On Fri, Jun 30, 2006 at 10:58:57AM +0200, Michael Hunold wrote:
> Hi,
> 
> please have a look at the attached program.
> 
> It uses the pthread library, creates a mutex, locks the mutex and the
> calls pthread_mutex_timedlock() which is expected to time out because
> the mutex is already locked, then calls pthread_mutex_timedlock() again,
> but this code should never be called.
> 
> I'm using uClibc 0.9.29 on a MIPS platform.
> 
> First I'm compiling the program the usual way as a shared executable:
> 
> /opt/uclibc/bin/mips-linux-uclibc-gcc -Wall timedlock.c -o timedlock
> -lpthread
> 
> On my target I get the expected result:
> 
> /target $ ./ldd timedlock
> ldd: can't open cache '/etc/ld.so.cache'
>         libpthread.so.0 => /lib/libpthread.so.0 (0x2aaee000)
>         libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x2ab43000)
>         libc.so.0 => /lib/libc.so.0 (0x2ab91000)
>         ld-uClibc.so.0 => /lib/ld-uClibc.so.0 (0x2aaa8000)
> /target $ ./timedlock
> main(): trying to lock mutex
> main(): pthread_mutex_lock() ok
> main(): pthread_mutex_timedlock() timeout
> 
> When I use "-nodefaultlibs -lc -lpthread", however, things are different.
> 
> /opt/uclibc/bin/mips-linux-uclibc-gcc -Wall timedlock.c -o timedlock
> -nodefaultlibs -lc -lpthread

Yes, you're linking the libs in the wrong order. Put -lpthread -lc and
everything will be fine.

Rich




More information about the uClibc mailing list