Thread: lpthread errors while compiling 8.0beta

lpthread errors while compiling 8.0beta

From
Robert Treat
Date:
Worked through some troubles on irc last night, thought I would post it in 
case anyone else sees something similar. 

system is Slackware 8.1, Linux phppgadmin 2.4.18 #2 Fri May 31 01:21:23 PDT 
2002 i586 unknown

./configure was run with '--prefix=/usr/local/pgsql-8.0.0' '--enable-debug' 
'--enable-depend' '--enable-cassert' '--enable-thread-safety' '--with-tcl' 
'--without-tk' '--with-python'   which worked fine on 7.0 - 7.4, and seemed 
to work ok, however when running make I got the following:

make[4]: Leaving directory `/usr/local/src/postgresql-8.0.0beta1/src/port'
gcc -O2 -fno-strict-aliasing -g -Wall -Wmissing-prototypes 
-Wmissing-declarations -DFRONTEND -I../../../src/interfaces/libpq 
-I../../../src/include -D_GNU_SOURCE   -c -o initdb.o initdb.c -MMD
rm -f dirmod.c && ln -s ../../../src/port/dirmod.c .
gcc -O2 -fno-strict-aliasing -g -Wall -Wmissing-prototypes 
-Wmissing-declarations -DFRONTEND -I../../../src/interfaces/libpq 
-I../../../src/include -D_GNU_SOURCE   -c -o dirmod.o dirmod.c -MMD
rm -f exec.c && ln -s ../../../src/port/exec.c .
gcc -O2 -fno-strict-aliasing -g -Wall -Wmissing-prototypes 
-Wmissing-declarations -DFRONTEND -I../../../src/interfaces/libpq 
-I../../../src/include -D_GNU_SOURCE   -c -o exec.o exec.c -MMD
gcc -O2 -fno-strict-aliasing -g -Wall -Wmissing-prototypes 
-Wmissing-declarations initdb.o dirmod.o exec.o 
-L../../../src/interfaces/libpq -lpq -L../../../src/port  
-Wl,-rpath,/usr/local/pgsql-8.0.0/lib -lpgport -lz -lreadline -ltermcap 
-lcrypt -lresolv -lnsl -ldl -lm  -o initdb
../../../src/interfaces/libpq/libpq.so: undefined reference to 
`pthread_getspecific'
../../../src/interfaces/libpq/libpq.so: undefined reference to `pthread_once'
../../../src/interfaces/libpq/libpq.so: undefined reference to 
`pthread_key_create'
../../../src/interfaces/libpq/libpq.so: undefined reference to 
`pthread_setspecific'
collect2: ld returned 1 exit status
make[3]: *** [initdb] Error 1
make[3]: Leaving directory 
`/usr/local/src/postgresql-8.0.0beta1/src/bin/initdb'
make[2]: *** [all] Error 2
make[2]: Leaving directory `/usr/local/src/postgresql-8.0.0beta1/src/bin'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/usr/local/src/postgresql-8.0.0beta1/src'
make: *** [all] Error 2

so I went back and checked the relevant parts of configure which told me:
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... no
checking for cc_r... gcc
checking pthread.h usability... yes
checking pthread.h presence... yes
checking for pthread.h... yes

but I was pretty sure I had lpthread library on my machine (and verified this 
with some help from irc).   however Makefile.global told me 

PTHREAD_CFLAGS          = -pthread -D_REENTRANT -D_THREAD_SAFE 
-D_POSIX_PTHREAD_SEMANTICS
PTHREAD_LIBS            =

so I added -lpthread to the PTHREAD_LIBS line and it all compiled ok and 
passed regression.   one theory of where the problem lies focused on this bit 
of config.log:

configure:13260: checking for the pthreads library -lpthreads
configure:13301: gcc -o conftest -O2 -fno-strict-aliasing -g  -D_GNU_SOURCE    
conftest.c -lpthreads -lz -lreadline -ltermcap -lcrypt -lresolv -lnsl -ldl 
-lm  >&5
/usr/i386-slackware-linux/bin/ld: cannot find -lpthreads
collect2: ld returned 1 exit status
configure:13304: $? = 1
configure: failed program was:

noteably that it should have been using -lpthread not -lpthreads.  that might 
be a typo, or might be some type of configure error since I know some 
platforms use -lpthreads, but I'm not sure, maybe someone else can put the 
info to good use. 

-- 
Robert Treat
Build A Better Lamp :: Linux Apache {middleware} PostgreSQL


Re: lpthread errors while compiling 8.0beta

From
Shridhar Daithankar
Date:
On Monday 09 Aug 2004 9:18 pm, Robert Treat wrote:
> but I was pretty sure I had lpthread library on my machine (and verified
> this with some help from irc).   however Makefile.global told me
>
> PTHREAD_CFLAGS          = -pthread -D_REENTRANT -D_THREAD_SAFE
> -D_POSIX_PTHREAD_SEMANTICS
> PTHREAD_LIBS            =
>
> so I added -lpthread to the PTHREAD_LIBS line and it all compiled ok and
> passed regression.   one theory of where the problem lies focused on this
> bit of config.log:
>
> configure:13260: checking for the pthreads library -lpthreads
> configure:13301: gcc -o conftest -O2 -fno-strict-aliasing -g  -D_GNU_SOURCE
> conftest.c -lpthreads -lz -lreadline -ltermcap -lcrypt -lresolv -lnsl -ldl
> -lm  >&5
> /usr/i386-slackware-linux/bin/ld: cannot find -lpthreads
> collect2: ld returned 1 exit status
> configure:13304: $? = 1
> configure: failed program was:

I noticed it on a slackware 9.1 system as well. I didn't noticed the above 
part but I had to change Makefile.global.

My hypothesis was linuxthreads does not transmit libpthread.so dependency 
correctly.(Out of memory, found while reading on differences between NTPL and 
linuxthreads. Don't remember the exact source now). 

I got a failure while linking initdb because it was linking against libpq, 
which in turn linking against libpthreads.so. So in order to close the 
linking unit, the linker needs -lpthreads mentioned against initdb(or in 
global linker flags).

NTPL can take care of this situation IIRC. 

Since linuxthreads are becoming extinct rapidly(barring slackware and may be 
debian, of course), I didn't chase the issue much. May be we need to document 
this.
Shridhar