Skip to content

Commit e48322a

Browse files
committed
Be more aggressive about adding flags to thread compiles. The configure
test only tests for building a binary, not building a shared library. On Linux, you can build a binary with -pthread, but you can't build a binary that uses a threaded shared library unless you also use -pthread when building the binary, or adding -lpthread to the shared library build. This patch has the effect of doing the later by adding both -pthread and -lpthread when building libpq.
1 parent 19f1370 commit e48322a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

config/acx_pthread.m4

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,26 +89,29 @@ for flag in $acx_pthread_flags; do
8989
9090
-*)
9191
AC_MSG_CHECKING([whether pthreads work with $flag])
92-
PTHREAD_CFLAGS="$flag"
92+
tryPTHREAD_CFLAGS="$flag"
9393
;;
9494
9595
pthread-config)
96+
# skip this if we already have flags defined, for PostgreSQL
97+
if test x"$PTHREAD_CFLAGS" != x -o x"$PTHREAD_LIBS" != x; then continue; fi
9698
AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
9799
if test x"$acx_pthread_config" = xno; then continue; fi
98-
PTHREAD_CFLAGS="`pthread-config --cflags`"
99-
PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
100+
tryPTHREAD_CFLAGS="`pthread-config --cflags`"
101+
tryPTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
102+
fi
100103
;;
101104
102105
*)
103106
AC_MSG_CHECKING([for the pthreads library -l$flag])
104-
PTHREAD_LIBS="-l$flag"
107+
tryPTHREAD_LIBS="-l$flag"
105108
;;
106109
esac
107110
108111
save_LIBS="$LIBS"
109112
save_CFLAGS="$CFLAGS"
110-
LIBS="$PTHREAD_LIBS $LIBS"
111-
CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
113+
LIBS="$tryPTHREAD_LIBS $PTHREAD_LIBS $LIBS"
114+
CFLAGS="$CFLAGS $PTHREAD_CFLAGS $tryPTHREAD_CFLAGS"
112115
113116
# Check for various functions. We must include pthread.h,
114117
# since some functions may be macros. (On the Sequent, we
@@ -130,11 +133,13 @@ for flag in $acx_pthread_flags; do
130133
131134
AC_MSG_RESULT($acx_pthread_ok)
132135
if test "x$acx_pthread_ok" = xyes; then
133-
break;
136+
# we continue with more flags because Linux needs -lpthread
137+
# for libpq builds on PostgreSQL. The test above only
138+
# tests for building binaries, not shared libraries.
139+
PTHREAD_LIBS=" $tryPTHREAD_LIBS $PTHREAD_LIBS"
140+
PTHREAD_CFLAGS="$PTHREAD_CFLAGS $tryPTHREAD_CFLAGS"
134141
fi
135142
136-
PTHREAD_LIBS=""
137-
PTHREAD_CFLAGS=""
138143
done
139144
fi
140145

0 commit comments

Comments
 (0)