git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] In configure.ac, try -lpthread in $LIBS instead of $CFLAGS to make picky linkers happy

From
RCRainer M. Canavan <git@canavan.de>
Date
Nov 6, 2015, 01:11 UTC
Message-ID
<201511060111.tA61BbFX084361@tezro.nonet>
In-Reply-To
<vpqa8qwst4y.fsf@anie.imag.fr>

Some linkers, namely the one on IRIX are rather strict concerning the order or arguments for symbol resolution, i.e. no libraries listed before objects or other libraries on the command line are considered for symbol resolution. Therefore, -lpthread can't work if it's put in CFLAGS, because it will not be considered for resolving pthread_key_create in conftest.o. Use $LIBS instead.

Signed-off-by: Rainer Canavan <git@canavan.de>
---
 configure.ac | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index fd22d41..1f55009 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1149,7 +1149,12 @@ elif test -z "$PTHREAD_CFLAGS"; then
   # would then trigger compiler warnings on every single file we compile.
   for opt in "" -mt -pthread -lpthread; do
      old_CFLAGS="$CFLAGS"
-     CFLAGS="$opt $CFLAGS"
+     old_LIBS="$LIBS"
+     case "$opt" in
+        -l*)  LIBS="$opt $LIBS" ;;
+        *)    CFLAGS="$opt $CFLAGS" ;;
+     esac
+
      AC_MSG_CHECKING([for POSIX Threads with '$opt'])
      AC_LINK_IFELSE([PTHREADTEST_SRC],
 	[AC_MSG_RESULT([yes])
@@ -1161,6 +1166,7 @@ elif test -z "$PTHREAD_CFLAGS"; then
 	],
 	[AC_MSG_RESULT([no])])
       CFLAGS="$old_CFLAGS"
+      LIBS="$old_LIBS"
   done
   if test $threads_found != yes; then
     AC_CHECK_LIB([pthread], [pthread_create],
-- 
2.6.2
Previous: Matthieu MoyNext: Matthieu Moy
Message 3 of 7 in “configure: -lpthread doesn't belong in CFLAGS”
  1. Rainer M. CanavanNov 1, 2015
  2. Matthieu MoyNov 2, 2015
  3. In configure.ac, try -lpthread in $LIBS instead of $CFLAGS to make picky linkers happyRainer M. Canavan, Nov 6, 2015
  4. Matthieu MoyNov 6, 2015
  5. configure.ac: try -lpthread in $LIBS instead of $CFLAGSRainer M. Canavan, Nov 8, 2015
  6. Matthieu MoyNov 8, 2015
  7. Jeff KingNov 20, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.