Linking to pthreads: undefined reference to __builtin_expect

Hi,

The following C program compiles using PGI 7.1.4 on RHEL4u6, but doesn’t on CentOS5.2 (in either 32- or 64-bit modes):

#include <pthread.h>
int main () {
    pthread_t th=pthread_self();

    pthread_join(th, 0);
    pthread_attr_init(0);

    pthread_cleanup_push(0, 0);
    pthread_create(0,0,0,0);
    pthread_cleanup_pop(0);

    return 0;
}

Instead, I get the following compilation error:

$ pgcc -o pthread_test pthread_test.c -lpthread
pthread_test.c:
pthread_test.o: In function `main':
pthread_test.c:(.text+0x52): undefined reference to `__builtin_expect'

Any ideas why?

OpenMPI 1.2.6’s configure script uses this to determine whether a system has threading support or not.

Cheers,

Mark

I don’t know why it would work in RHEL and not a newer CENTOS, but the PGI release notes state that in 7.2-2, it is fixed.

14942 32/64-bit C/C++
C compiler gets unresolved reference to __builtin_expect
pgcc now recognizes the gcc extension, __builtin_expect()

Bernie Borenstein
The Boeing Company

Doh. Thanks: I’ll read later release notes in future ;)

Cheers,

Mark

Hi Mark,

Bernie is correct that we recently added support for the GCC C extension “__builtin_expect” to the 7.2-2 pgcc compiler. I believe GNU added this builtin to either their 4.0 or 4.1 compilers and explains why you did not get this error with RHEL4 which uses gcc version 3.4.

  • Mat