在c ++中使用pthread

ogz*_*ylz 14 c++ linker pthreads linker-errors

pthread.h在一个*.cc文件中使用.当我尝试使用pthread_exit(0);pthread_join(mythrds[yy],NULL);它说:

.cc:(.text+0x3e): undefined reference to `pthread_exit'
Run Code Online (Sandbox Code Playgroud)

*.c使用gcc 在文件中编译非常相似的代码时,它工作得很完美.我如何在c ++中使用pthread ..(我还添加了-lpthread)

..
void *myThreads ( void *ptr )
{
...
pthread_exit(0); 
}
..
Run Code Online (Sandbox Code Playgroud)

标志:

g++ -lpthread -Wall -static -W -O9 -funroll-all-loops -finline -ffast-math
Run Code Online (Sandbox Code Playgroud)

Whi*_*ind 29

您可以尝试使用-pthread选项来g ++.

   -pthread
       Adds support for multithreading with the pthreads library.  This
       option sets flags for both the preprocessor and linker.
Run Code Online (Sandbox Code Playgroud)