Linking to pthread library: undefined reference

Gergely CZUCZY phoemix at harmless.hu
Fri Jun 15 17:42:42 UTC 2007


On Fri, Jun 15, 2007 at 07:01:19PM +0200, Frank Behrens wrote:
> Hi,
> 
> I could not find any information in the developers handbook, so I ask here for support.
> 
> I try to link an milter (sendmail mail filter) test application and get an error I do not 
> understand. I use FreeBSD 6.2-STABLE-200705211513 with an userland from May-03.
> In my Makefile I have:
> CFLAGS+=	-I/usr/local/include -std=c99 -pthread -v
> LDADD+=		-L/usr/local/lib -lmilter
> 
> This gives linker command:
> cc -O2 -pipe -fno-strict-aliasing -march=pentium4 -I/usr/local/include -std=c99 -pthread -v -g -
> DDEBUG=1 -O1 -fno-omit-frame-pointer -Wsystem-headers -Wall -Wno-format-y2k -W -
> Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Wreturn-
> type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wcast-align -Wunused-parameter -
> Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls  -o fmilter fmilter.o -
> L/usr/local/lib -lmilter
> Using built-in specs.
> Configured with: FreeBSD/i386 system compiler
> Thread model: posix
> gcc version 3.4.6 [FreeBSD] 20060305
>  /usr/bin/ld -V -dynamic-linker /libexec/ld-elf.so.1 -o fmilter /usr/lib/crt1.o /usr/lib/crti.o 
> /usr/lib/crtbegin.o -L/usr/local/lib -L/usr/lib fmilter.o -lmilter -lgcc -lpthread -lc -lgcc 
I don't think this is the problem here, but you should link against -pthread, and
not -lpthread. pthread is just an API here, while -pthread refers to the
system-default threading library (with a pthread interface).

> /usr/lib/crtend.o /usr/lib/crtn.o
> GNU ld version 2.15 [FreeBSD] 2004-05-23
>   Supported emulations:
>    elf_i386_fbsd
> /usr/lib/libmilter.so: undefined reference to `pthread_detach'
> 
> In my opinion the symbol should be found in
> /usr/lib/libpthread.so@ -> /lib/libpthread.so.2
> 
> When I look into the libraries I see
> > objdump -T /usr/lib/libmilter.so | fgrep detach
> 00000000      D  *UND*  00000000 pthread_detach
> 
> > objdump -T /usr/lib/libpthread.so | fgrep pthread_detach
> 000077d4  w   DF .text  000003a4  LIBTHREAD_1_0 pthread_detach
> 000077d4 g    DF .text  000003a4  LIBTHREAD_1_0 _pthread_detach
> 
> 
> Did I make something wrong? I guess yes, but what?
> 
> Thanks for your help and best regards,
>    Frank
> -- 
> Frank Behrens, Osterwieck, Germany
> PGP-key 0x5B7C47ED on public servers available.
> 
> _______________________________________________
> freebsd-threads at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-threads
> To unsubscribe, send any mail to "freebsd-threads-unsubscribe at freebsd.org"
> 

Bye,

Gergely Czuczy
mailto: gergely.czuczy at harmless.hu

-- 
Weenies test. Geniuses solve problems that arise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 2307 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-threads/attachments/20070615/97e16cea/attachment.pgp


More information about the freebsd-threads mailing list