While building Thomas Boutell's excellent libgd library (ver 2.0.33) on FreeBSD 4.11, I ran into a problem that Google shows lots of others have had, but without a solution. After configuring the library for the platform, undefined pthread variables are found:
$ make ... /usr/local/bin/bash ./libtool --mode=link gcc -g -O2 -L/usr/local/lib \ -L/usr/local/lib -o annotate annotate.o ./libgd.la -ljpeg -lfreetype -lpng \ -lz -lm /usr/local/lib/libiconv.so -Wl,-rpath -Wl,/usr/local/lib gcc -g -O2 -o .libs/annotate annotate.o /usr/local/lib/libiconv.so \ -Wl,-rpath -Wl,/usr/local/lib -L/usr/local/lib ./.libs/libgd.so \ -ljpeg -lfreetype -lpng -lz -lm -Wl,--rpath -Wl,/usr/local/lib ./.libs/libgd.so: undefined reference to `pthread_mutex_unlock' ./.libs/libgd.so: undefined reference to `pthread_mutex_destroy' ./.libs/libgd.so: undefined reference to `pthread_mutex_lock' ./.libs/libgd.so: undefined reference to `pthread_mutex_init' *** Error code 1
Looking around found no libpthread.a library - huh? - in any of its forms, but it was hard to imagine that this machine simply didn't have this facility.
Several hours of hunting this down showed the problem: pthreads are found in libc_r (the re-entrant C library). Aha! This is enabled with the -pthread flag to gcc.
I typically use a simple wrapper script around ./configure so that I can document my settings, and I just added CFLAGS="-pthread" to the ../configure-gd script:
# # requires LIBPNG # # sh ../configure-gd # make # make check # sudo make install # export CFLAGS='-pthread' # for FreeBSD exec ./configure \ --without-x
The proper solution is to fix the configure.ac script to check for this properly, but it looks like very ugly territory; many flavors and variants and workarounds. Sadly, not up for that today.
I'm documenting this here mainly so Google will index it and perhaps help some future GD-builder who's been having the same problem.





Well, your goal has been met. I've fought this multiple times and finally decided to give it one last go at a deep Google search. It's a shame this wasn't indexed higher as it's right on the money! Thanks much for sharing your experience.
Posted by: Tim Provencio | July 25, 2005 at 07:14 PM
You my friend deserve a medal, finally managed to find this post after days of trying to get GD to compile. I skipped over this bit earlier on as ./configure said it detected '-pthread' as the switch. Ah well! It compiled this time.
Thanks for that.
Posted by: Alex | September 22, 2005 at 09:35 PM
Very good - I'd I'll take the "wrapper tip" onboard. Must add a link to my site to give you some google juice!
Posted by: Steve Welham | October 03, 2005 at 07:49 AM
Dude, you the man!
setenv CFLAGS -pthreads then redid ./configure so that it read the variable and my compilation problem went away.
Posted by: Very Grateful Reader | December 01, 2005 at 07:46 PM
Yep, this is brilliant advice and has worked for me.
Now I'm having a similar problem when I'm trying to install and run the Perl GD library. It builds OK but all the tests fail with things like:
t/GD..........Can't load './blib/arch/auto/GD/GD.so' for module GD: /usr/local/gd-2.0.33/lib/libgd.so.2: Undefined symbol "pthread_mutex_unlock" at /usr/local/perl-5.8.4/lib/5.8.4/i386-freebsd/DynaLoader.pm line 230.
at t/GD.t line 14
Hmmmm.
Posted by: Jesse Reynolds | September 10, 2006 at 01:56 AM