Search code examples
c++gccposixaix

Compile pthread.h stuff on AIX using g++


I try to compile this very simplified program:

#include <pthread.h>

int main(){
    pthread_yield();
    return 0;
}

using -pthread like the IBM side says:

$ g++ -pthread test.cpp -o test

and get this error:

test.cpp: In function 'int main()':
test.cpp:4:15: error: 'pthread_yield' was not declared in this scope
pthread_yield();

I tried lots of other falgs too, but nothing worked so far. The pthread.h is in /usr/includes but pthread_yield() needs _AIX_PTHREADS_D7 defined. Do I have to define this myselfe or is this done by adding some flag?

THX!


Solution

  • Other than defining symbol _AIX_PTHREADS_D7 you have to use library libpthreads_compat as well.

    g++ -o marscode marscode.cc -D_AIX_PTHREADS_D7 -lpthreads_compat -lpthreads