使用g ++在AIX上编译pthread.h

问题描述 投票:0回答:1

我尝试编译这个非常简化的程序:

#include <pthread.h>

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

像IBM那样使用-pthread说:

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

并得到此错误:

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

我也尝试了很多其他的谬误,但到目前为止还没有任何效果。 pthread.h位于/ usr / includes中,但pthread_yield()需要定义_AIX_PTHREADS_D7。我必须定义这个myselfe还是通过添加一些标志来完成?

谢谢!

c++ gcc posix aix
1个回答
1
投票

除了定义符号_AIX_PTHREADS_D7之外,您还必须使用库libpthreads_compat

g++ -o marscode marscode.cc -D_AIX_PTHREADS_D7 -lpthreads_compat -lpthreads
© www.soinside.com 2019 - 2024. All rights reserved.