Building LIBGD on FreeBSD
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.