autoconf
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Configure not selecting proper -pthread options


From: Jeff Fulmer
Subject: Re: Configure not selecting proper -pthread options
Date: Thu, 14 Apr 2005 18:29:22 -0400
User-agent: Mutt/1.4.1i

Here's how I rolled it:

dnl
dnl make sure AIXers have the proper compiler
case "$host_os" in
  *aix*)
    if test -n "${CC}" ; then
      AC_CHECK_PROGS(CC_R, xlc_r cc_r cc)
      if test "$CC_R" = cc ; then
        AC_MSG_ERROR([pthread support requires cc_r (or other suitable 
compiler) on AIX])
      else
        CC=$CC_R
        AC_SUBST(CC)
      fi
    fi
  ;;
esac



dnl
dnl Check for pthread support
dnl
PTHREAD_CFLAGS=error
PTHREAD_LDFLAGS=error

dnl If it's error, then the user didn't 
dnl define it.
if test "x$PTHREAD_LDFLAGS" = xerror; then
  AC_CHECK_LIB(pthread, pthread_attr_init, [
             PTHREAD_CFLAGS="-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
             PTHREAD_LDFLAGS="-lpthread" ])
fi

if test "x$PTHREAD_LDFLAGS" = xerror; then
  AC_CHECK_LIB(pthreads, pthread_attr_init, [
             PTHREAD_CFLAGS="-D_THREAD_SAFE"
             PTHREAD_LDFLAGS="-lpthreads" ])
fi

if test "x$PTHREAD_LDFLAGS" = xerror; then
   AC_CHECK_LIB(c_r, pthread_attr_init, [
                PTHREAD_CFLAGS="-D_THREAD_SAFE -pthread"
                PTHREAD_LDFLAGS="-pthread" ])
fi

if test "x$PTHREAD_LDFLAGS" = xerror; then
   AC_CHECK_FUNC(pthread_attr_init, [
                 PTHREAD_CFLAGS="-D_REENTRANT"
                 PTHREAD_LDFLAGS="-lpthread" ])
fi

if test $PTHREAD_LDFLAGS = "error"; then
  AC_MSG_WARN(pthread library NOT found: guessing and hoping for the
best....)
  PTHREAD_CFLAGS="-D_REENTRANT"
  PTHREAD_LDFLAGS="-lpthread"
fi

AC_SUBST(PTHREAD_CFLAGS)
AC_SUBST(PTHREAD_LDFLAG)



On Thu, Apr 14, 2005 at 05:03:32PM -0400, Kevin Teich wrote:
> Hello,
> 
> I've noticed some strange behavior with the options that configure chooses 
> for compiling pthread code. I'm on a Red Hat Linux 7.3 machine using 
> autoconf 2.57 and automake 1.6.3.
> 
> We use the ACX_PTHREAD macro from ac-archive to configure pthread options, 
> from http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.html . 
> configure would execute successfully and determine that -pthread was the 
> correct option for this machine, but our programs would not compile, the 
> Makefiles generating link errors for undefined pthread symbols.
> 
> The reason for this is that when configure does its test to figure out how 
> to handle pthreads, it uses a combined compile/link line when testing 
> various options. The test it does for -pthread is to set CFLAGS to 
> -pthread and leave LIBS blank, and it generates a test like this:
> 
> gcc -c -o conftest -pthread test.c
> 
> This compiles fine, presumably because gcc breaks this down into two 
> separate steps:
> 
> gcc -c test.c -pthread
> gcc -o conftest test.o -pthread
> 
> So configure sets PTHREAD_CFLAGS to -pthread and PTHREAD_LIBS to nothing.
> 
> But, gcc wants -pthread on both its compile line and its link line. I 
> don't know enough about gcc to know why, but I've verified it with a tiny 
> test program on my own. (For the link line, you can acutally use -pthread 
> or -lpthread.)
> 
> So when the generated makefile starts building stuff, it does it in the 
> normal two steps. So we'd get something like:
> 
> gcc -c main.c $PTHREADS_CFLAGS        (= -pthread)
> gcc -o main $PTHREADS_LIBS            (= empty)
> 
> And get a link error. So I added some code to the acinclude.m4 that checks 
> to see if configure determined that -pthread was the thing to use, and if 
> so, to also add it to PTHREAD_LIBS:
> 
> if test x"$PTHREAD_CFLAGS" = x-pthread; then
>   PTHREAD_LIBS="-pthread"
> fi
> 
> This solved our problem.
> 
> Is this a bug, or a logic error in the ACX_PTHREAD macro, or a 
> misconfiguration on my part? Did I do the correct thing to fix it, or is 
> there another work-around?
> 
> Thanks.
> 
> 
> -- 
> Kevin Teich
> 
> 
> 
> _______________________________________________
> Autoconf mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/autoconf
> 

-- 
#include <stdio.h>
int main(){int a[]={74,117,115,116,32,97,110,111,116,104,101,114,32, \
67,32,104,97,99,107,101,114,10,0}; int *b=a;while(*b>0)putchar(*b++);}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]