Thread: 8.0.0beta1: -lpthread missing

8.0.0beta1: -lpthread missing

From
Martin Münstermann
Date:
System Configuration
---------------------  Architecture (example: Intel Pentium)         : Intel Pentium
  Operating System (example: Linux 2.4.18)      : Linux 2.4.21-grsec
(Debian)
  PostgreSQL version (example: PostgreSQL-8.0):   PostgreSQL-8.0.0-beta1
  Compiler used (example:  gcc 2.95.2)          : 2.95.4


Please enter a FULL description of your problem:
------------------------------------------------
When configuring --enable-thread-safety the binaries cannot be linked:
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations initdb.o dirmod.o exe
c.o -L../../../src/interfaces/libpq -lpq -L../../../src/port
-Wl,-rpath,/opt/postgresql-800beta1/li
b -lpgport -lz -lreadline -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



Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------
# ./configure --prefix=/opt/postgresql-800beta1 --enable-thread-safety
# make


If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------
The binaries must be linked with pthread (-lpthread).


Regards, Martin



Re: 8.0.0beta1: -lpthread missing

From
Robert Treat
Date:
On Tuesday 10 August 2004 05:14, Martin M=FCnstermann wrote:
> System Configuration
> ---------------------
>    Architecture (example: Intel Pentium)         : Intel Pentium
>
>    Operating System (example: Linux 2.4.18)      : Linux 2.4.21-grsec
> (Debian)
>
>    PostgreSQL version (example: PostgreSQL-8.0):   PostgreSQL-8.0.0-beta1
>
>    Compiler used (example:  gcc 2.95.2)          : 2.95.4
>
>
> Please enter a FULL description of your problem:
> ------------------------------------------------
> When configuring --enable-thread-safety the binaries cannot be linked:
> gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
> -Wmissing-declarations initdb.o dirmod.o exe
> c.o -L../../../src/interfaces/libpq -lpq -L../../../src/port
> -Wl,-rpath,/opt/postgresql-800beta1/li
> b -lpgport -lz -lreadline -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
>
>
>
> Please describe a way to repeat the problem.   Please try to provide a
> concise reproducible example, if at all possible:
> ----------------------------------------------------------------------
> # ./configure --prefix=3D/opt/postgresql-800beta1 --enable-thread-safety
> # make
>
>
> If you know how this problem might be fixed, list the solution below:
> ---------------------------------------------------------------------
> The binaries must be linked with pthread (-lpthread).
>

Can you take a look at the thread below and report back if that fixes your=
=20
problem?  http://archives.postgresql.org/pgsql-hackers/2004-08/msg00525.php

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

Re: 8.0.0beta1: -lpthread missing

From
Bruce Momjian
Date:
In fact, backup in the output and look at the flags used to build libpq.
Are they correct?  If they are, you shouldn't need any additional flags
when building initdb because initdb doesn't call any threaded functions,
_except_ if you have that limitation that a libpq using threads requries
a thread flag for everything that calls libpq.

Please report back.

---------------------------------------------------------------------------

Robert Treat wrote:
> On Tuesday 10 August 2004 05:14, Martin M?nstermann wrote:
> > System Configuration
> > ---------------------
> >    Architecture (example: Intel Pentium)         : Intel Pentium
> >
> >    Operating System (example: Linux 2.4.18)      : Linux 2.4.21-grsec
> > (Debian)
> >
> >    PostgreSQL version (example: PostgreSQL-8.0):   PostgreSQL-8.0.0-beta1
> >
> >    Compiler used (example:  gcc 2.95.2)          : 2.95.4
> >
> >
> > Please enter a FULL description of your problem:
> > ------------------------------------------------
> > When configuring --enable-thread-safety the binaries cannot be linked:
> > gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
> > -Wmissing-declarations initdb.o dirmod.o exe
> > c.o -L../../../src/interfaces/libpq -lpq -L../../../src/port
> > -Wl,-rpath,/opt/postgresql-800beta1/li
> > b -lpgport -lz -lreadline -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
> >
> >
> >
> > Please describe a way to repeat the problem.   Please try to provide a
> > concise reproducible example, if at all possible:
> > ----------------------------------------------------------------------
> > # ./configure --prefix=/opt/postgresql-800beta1 --enable-thread-safety
> > # make
> >
> >
> > If you know how this problem might be fixed, list the solution below:
> > ---------------------------------------------------------------------
> > The binaries must be linked with pthread (-lpthread).
> >
>
> Can you take a look at the thread below and report back if that fixes your
> problem?  http://archives.postgresql.org/pgsql-hackers/2004-08/msg00525.php
>
> --
> Robert Treat
> Build A Better Lamp :: Linux Apache {middleware} PostgreSQL
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: 8.0.0beta1: -lpthread missing

From
Bruce Momjian
Date:
Robert Treat wrote:
> > `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
> >
> >
> >
> > Please describe a way to repeat the problem.   Please try to provide a
> > concise reproducible example, if at all possible:
> > ----------------------------------------------------------------------
> > # ./configure --prefix=/opt/postgresql-800beta1 --enable-thread-safety
> > # make
> >
> >
> > If you know how this problem might be fixed, list the solution below:
> > ---------------------------------------------------------------------
> > The binaries must be linked with pthread (-lpthread).
> >
>
> Can you take a look at the thread below and report back if that fixes your
> problem?  http://archives.postgresql.org/pgsql-hackers/2004-08/msg00525.php

I looked at that.  The line that does the tests is in
config/acx_pthread.m4:

    acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread
    -pthreads -mthreads pthread --thread-safe -mt pthread-conf ig"

so you should see that list tried.  Does that help?

I am majorly concerned that Slackware has the same problem as Unixware,
meaning that if you use threading in the lib, you now need the flags on
every applicaiton that uses the lib.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: 8.0.0beta1: -lpthread missing

From
Bruce Momjian
Date:
OK, I have some more information.  Basically, the config/acx_pthread.m4
manual page (http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.html)
says:

    NOTE: You are assumed to not only compile your program with these flags,
    but also link it with them as well. e.g. you should link with
    $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS

meaning if -lpthread is defined in PTHREAD_CFLAGS, it also has to be
included in the link.  Now, from your reports you said -lpthread was in
PTHREAD_CFLAGS, so why isn't it also included in the libpq link line.  I
need to see your link line output for libpq.

If I add -g3 in interfaces/libpq/Makefile:

    override CFLAGS += $(PTHREAD_CFLAGS) -g3

I see -g3 in the libpq link line:

    gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
    -Wmissing-declarations -O1 -Wall -Wmissing-prototypes
    -Wmissing-declarations -Wpointer-arith -Wcast-align -D_REENTRANT
    -D_THREAD_SAFE -D_POSIX_PTHREAD_SEMANTICS -g3 -fpic -shared

                                                  ^^^
    -Wl,-x,-soname,libpq.so.3 fe-auth.o fe-connect.o fe-exec.o fe-misc.o
    fe-print.o fe-lobj.o fe-protocol2.o fe-protocol3.o pqexpbuffer.o
    pqsignal.o fe-secure.o dllist.o md5.o ip.o wchar.o encnames.o noblock.o
    pgstrcasecmp.o thread.o  -L../../../src/port -L/usr/local/lib
    -L/usr/contrib/lib -lintl -lssl -lcrypto  -lc
    -Wl,-rpath,/usr/local/pgsql/lib -o libpq.so.3.2

Do you see similar behavior in Slackware?  I assumed all compilers would
use $CFLAGS in their link lines.

---------------------------------------------------------------------------

Martin Münstermann wrote:
> Hello!
>
> Bruce Momjian wrote:
> > Robert Treat wrote:
> >
> >>>`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
> >>>
> >>>
> >>>
> >>>Please describe a way to repeat the problem.   Please try to provide a
> >>>concise reproducible example, if at all possible:
> >>>----------------------------------------------------------------------
> >>># ./configure --prefix=/opt/postgresql-800beta1 --enable-thread-safety
> >>># make
> >>>
> >>>
> >>>If you know how this problem might be fixed, list the solution below:
> >>>---------------------------------------------------------------------
> >>>The binaries must be linked with pthread (-lpthread).
> >>>
> >>
> >>Can you take a look at the thread below and report back if that fixes your
> >>problem?  http://archives.postgresql.org/pgsql-hackers/2004-08/msg00525.php
>
> Yes, adding -lpthread to PTHREAD_LIBS and rebuilding solved the problem.
> Note: when doing so, libpq.so is built with -lpthread, PTHREAD_LIBS is
> *not* used in the makefiles of the client binaries like initdb and psql.
>
> > I looked at that.  The line that does the tests is in
> > config/acx_pthread.m4:
> >
> >     acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread
> >     -pthreads -mthreads pthread --thread-safe -mt pthread-conf ig"
> >
> > so you should see that list tried.  Does that help?
> >
> > I am majorly concerned that Slackware has the same problem as Unixware,
> > meaning that if you use threading in the lib, you now need the flags on
> > every applicaiton that uses the lib.
>
> At least on debian this is not the case (see above):
> -lpthread is used when building libpq.so.3.2.
> So the shared library contains a dependency on libpthread.so.
> Then the client apps do not need a -lpthread at build time. The dynamic
> linker will resolve the dependency on libpthread.so (via libpq.so) at
> runtime.
>
> Regards,
>   Martin
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Re: 8.0.0beta1: -lpthread missing

From
Martin Münstermann
Date:
Bruce Momjian wrote:
> OK, I have some more information.  Basically, the config/acx_pthread.m4
> manual page (http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.h=
> tml)
> says:
> =09
>     NOTE: You are assumed to not only compile your program with these flags,
>     but also link it with them as well. e.g. you should link with
>     $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
>
> meaning if -lpthread is defined in PTHREAD_CFLAGS, it also has to be
> included in the link.  Now, from your reports you said -lpthread was in
> PTHREAD_CFLAGS, so why isn't it also included in the libpq link line.  I
> need to see your link line output for libpq.

OK, here are parts of the output from configure --enable-thread-safety
on Debian:
[...]
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
[...]
--> configure thays, thate the CFLAG -pthread is sufficient.

Makefile.global:
PTHREAD_CFLAGS        = -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS
PTHREAD_LIBS        =


Let's look what make is doing:
[...]
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -I../../src/port -I../../src/include
-D_GNU_SOURCE  -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -c thread.c
ar crs libpgport.a dirmod.o exec.o noblock.o path.o pipe.o pgsleep.o
pgstrcasecmp.o sprompt.o thread.o

[...]

make[2]: Entering directory
`/home/user/checkout/postgresql-8.0.0beta1/src/interfaces'
make[3]: Entering directory
`/home/user/checkout/postgresql-8.0.0beta1/src/interfaces/libpq'
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-auth.o fe-auth.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-connect.o
fe-connect.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-exec.o fe-exec.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-misc.o fe-misc.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-print.o fe-print.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-lobj.o fe-lobj.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-protocol2.o
fe-protocol2.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-protocol3.o
fe-protocol3.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o pqexpbuffer.o
pqexpbuffer.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o pqsignal.o pqsignal.c
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o fe-secure.o fe-secure.c
rm -f dllist.c && ln -s ../../../src/backend/lib/dllist.c .
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o dllist.o dllist.c
rm -f md5.c && ln -s ../../../src/backend/libpq/md5.c .
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o md5.o md5.c
rm -f ip.c && ln -s ../../../src/backend/libpq/ip.c .
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o ip.o ip.c
rm -f wchar.c && ln -s ../../../src/backend/utils/mb/wchar.c .
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o wchar.o wchar.c
rm -f encnames.c && ln -s ../../../src/backend/utils/mb/encnames.c .
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o encnames.o encnames.c
rm -f noblock.c && ln -s ../../../src/port/noblock.c .
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o noblock.o noblock.c
rm -f pgstrcasecmp.c && ln -s ../../../src/port/pgstrcasecmp.c .
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o pgstrcasecmp.o
pgstrcasecmp.c
rm -f thread.c && ln -s ../../../src/port/thread.c .
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -I. -I../../../src/include
-D_GNU_SOURCE  -I../../../src/port -DFRONTEND  -c -o thread.o thread.c
ar crs libpq.a `lorder fe-auth.o fe-connect.o fe-exec.o fe-misc.o
fe-print.o fe-lobj.o fe-protocol2.o fe-protocol3.o pqexpbuffer.o
pqsignal.o fe-secure.o dllist.o md5.o ip.o wchar.o encnames.o noblock.o
pgstrcasecmp.o thread.o | tsort`
ranlib libpq.a
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -shared -Wl,-soname,libpq.so.3
fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o
dllist.o md5.o ip.o wchar.o encnames.o noblock.o pgstrcasecmp.o thread.o  -L../../../src/port -lcrypt -lresolv -lnsl
-Wl,-rpath,/opt/postgresql-800beta1/lib -o libpq.so.3.2
rm -f libpq.so.3
ln -s libpq.so.3.2 libpq.so.3
rm -f libpq.so
ln -s libpq.so.3.2 libpq.so
make[3]: Leaving directory
`/home/user/checkout/postgresql-8.0.0beta1/src/interfaces/libpq'

So the shared library is built with "-pthread"
[...]

gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations initdb.o dirmod.o exec.o
-L../../../src/interfaces/libpq -lpq -L../../../src/port
-Wl,-rpath,/opt/postgresql-800beta1/lib -lpgport -lz -lreadline -lcrypt
-lresolv -lnsl -ldl -lm  -o initdb

[--> results in linker error as described in the first posting]


The problem can be resolved, if I modify my Makefile.global to
PTHREAD_LIBS        = -lpthread

Then libpq.so is built with -lpthread (note the "l"):
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations -pthread -D_REENTRANT -D_THREAD_SAFE
-D_POSIX_PTHREAD_SEMANTICS -fpic -shared -Wl,-soname,libpq.so.3
fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o
fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o
dllist.o md5.o ip.o wchar.o encnames.o noblock.o pgstrcasecmp.o thread.o  -L../../../src/port -lcrypt -lresolv -lnsl
-lpthread 
-Wl,-rpath,/opt/postgresql-800beta1/lib -o libpq.so.3.2


The link line of initdb is unchanged, with the difference that there is
no error:
gcc -O2 -fno-strict-aliasing -Wall -Wmissing-prototypes
-Wmissing-declarations initdb.o dirmod.o exec.o
-L../../../src/interfaces/libpq -lpq -L../../../src/port
-Wl,-rpath,/opt/postgresql-800beta1/lib -lpgport -lz -lreadline -lcrypt
-lresolv -lnsl -ldl -lm  -o initdb


So for me it looks like in my case it's not sufficient to have the
compiler flag "-pthread", but also (or instead?) the linker flag
"-lpthread".
Maybe the case of a shared library using pthreads is not handled
correctly in the m4 macro?

Regards, Martin


Re: 8.0.0beta1: -lpthread missing

From
Martin Münstermann
Date:
Hello!

Bruce Momjian wrote:
> Robert Treat wrote:
>
>>>`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
>>>
>>>
>>>
>>>Please describe a way to repeat the problem.   Please try to provide a
>>>concise reproducible example, if at all possible:
>>>----------------------------------------------------------------------
>>># ./configure --prefix=/opt/postgresql-800beta1 --enable-thread-safety
>>># make
>>>
>>>
>>>If you know how this problem might be fixed, list the solution below:
>>>---------------------------------------------------------------------
>>>The binaries must be linked with pthread (-lpthread).
>>>
>>
>>Can you take a look at the thread below and report back if that fixes your
>>problem?  http://archives.postgresql.org/pgsql-hackers/2004-08/msg00525.php

Yes, adding -lpthread to PTHREAD_LIBS and rebuilding solved the problem.
Note: when doing so, libpq.so is built with -lpthread, PTHREAD_LIBS is
*not* used in the makefiles of the client binaries like initdb and psql.

> I looked at that.  The line that does the tests is in
> config/acx_pthread.m4:
>
>     acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread
>     -pthreads -mthreads pthread --thread-safe -mt pthread-conf ig"
>
> so you should see that list tried.  Does that help?
>
> I am majorly concerned that Slackware has the same problem as Unixware,
> meaning that if you use threading in the lib, you now need the flags on
> every applicaiton that uses the lib.

At least on debian this is not the case (see above):
-lpthread is used when building libpq.so.3.2.
So the shared library contains a dependency on libpthread.so.
Then the client apps do not need a -lpthread at build time. The dynamic
linker will resolve the dependency on libpthread.so (via libpq.so) at
runtime.

Regards, Martin