g++ ubuntu 多线程未定义引用

g++ ubuntu multithreading undefined reference

我正在 ubuntu 上编写一个创建一定数量线程的 c 代码 我已经添加了 pthreads 库但是当我 运行 代码 它以这个错误结束

Threads.cc:(.text+0x128): 未定义对 'pthread_create'

的引用

Threads.cc:(.text+0x15b): 未定义对 'pthread_join'

的引用

我正在使用 ubuntu 15.04 虚拟机。 我尝试了很多建议的解决方案,但没有一个有效! 任何帮助将不胜感激

I have already added pthreads library [..]

没有。你没有。如果你这样做了,你就不会遇到这个问题。您可能是想说您包含了 <pthread.h>。但这并不 link pthreads 库。

在编译选项的末尾添加 pthread。例如,

gcc -o out myfile.c -pthread