以下代码
#include <threads.h>
给我这个错误:
fatal error: threads.h: No such file or directory
使用最新的 GCC 和 Clang 以及 -std=c11。
GCC 和 Clang 不支持 C11 线程吗?或者是否有黑客(或需要安装的东西)来获取它?我只是使用 Ubuntu 14.04 以及 Ubuntu 存储库中的 gcc 和 clang 软件包。
最佳答案
gcc
文档 C11 status表明它不支持线程,它说:
Threading [Optional] | Library issue (not implemented)
正如文档所示,这实际上并不是 gcc
或 clang
问题,而是 glibc
问题。正如扎克指出的那样,它看起来像 there may be work under way soon获得对 glibc 的支持,但这现在对你没有帮助。
您可以使用this在此期间。
已修复 glibc 2.28
根据Bug 14092 - Support C11 threads这在 glibc 2.28 中已修复:
Implemented upstream by:
9d0a979 Add manual documentation for threads.h
0a07288 nptl: Add test cases for ISO C11 threads
c6dd669 nptl: Add abilist symbols for C11 threads
78d4013 nptl: Add C11 threads tss_* functions
918311a nptl: Add C11 threads cnd_* functions
3c20a67 nptl: Add C11 threads call_once functions
18d59c1 nptl: Add C11 threads mtx_* functions
ce7528f nptl: Add C11 threads thrd_* functionsIt will be included in 2.28.
关于C11 GCCthreads.h 未找到?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34806246/