xcode 找不到clang c11threads.h
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16244153/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
clang c11 threads.h not found
提问by Grady Player
I am trying to setup a c11 thread example in xcode... but it doesn't seem to have the threads.h header, though it isn't complaning about the macro described here:
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
我正在尝试在 xcode 中设置一个 c11 线程示例......但它似乎没有threads.h标头,尽管它并没有抱怨这里描述的宏:
http://www.open-std。 org/jtc1/sc22/wg14/www/docs/n1570.pdf
__STDC_NO_THREADS__The integer constant 1, intended to indicate that the implementation does not support the <threads.h> header.
__STDC_NO_THREADS__整数常量1,意在表明该实现不支持<threads.h>头文件。
回答by Grady Player
Looks like almost nothing supports the threads feature in C11... maybe I will try to get it into clang...
看起来几乎没有任何东西支持 C11 中的线程功能......也许我会尝试将它放入 clang......
回答by Jens Gustedt
With the clang on my machine (v. 3.2 on ubuntu/linux) that feature test macro isn't defined. Support for that feature will need support in the C library, that usually doesn't come with the compiler. So basically the answer for clang will not be much different than for gcc, they usually build upon the same C library, namely glibc, see here for answer for gcc.
随着我机器上的叮当声(ubuntu/linux 上的 3.2 版),未定义功能测试宏。对该功能的支持需要 C 库中的支持,这通常不随编译器一起提供。所以基本上 clang 的答案与 gcc 的答案没有太大不同,它们通常建立在相同的 C 库上,即 glibc,请参阅此处获取 gcc 的答案。
回答by chux - Reinstate Monica
it doesn't seem to have the
threads.h
header, though it isn't complaining
它似乎没有
threads.h
标题,虽然它没有抱怨
C11 has 2 specs about __STDC_NO_THREADS__
C11有2个规格关于 __STDC_NO_THREADS__
7.26 Threads
Implementations that define the macro__STDC_NO_THREADS__
need not provide this header nor support any of its facilities. C11 N1570 §7.26.1 2
__STDC_NO_THREADS__
The integer constant 1, intended to indicate that the implementation does not support the<threads.h>
header. C11 N1570 §6.10.8.3 1
7.26 线程
定义宏的实现__STDC_NO_THREADS__
不需要提供这个头文件,也不支持它的任何功能。C11 N1570 §7.26.1 2
__STDC_NO_THREADS__
整数常量 1,用于表示该实现不支持<threads.h>
标头。C11 N1570 §6.10.8.3 1
Per §7.26.1 2:
根据 §7.26.1 2:
#ifdef __STDC_NO_THREADS__
#error "No threading support"
#else
#include <threads.h>
#endif
Per §6.10.8.3:
根据 §6.10.8.3:
#if defined(__STDC_NO_THREADS) && __STDC_NO_THREADS__ == 1
#error "No threading support"
#else
#include <threads.h>
#endif
// Certainly this can be simplified to
#if defined(__STDC_NO_THREADS) && __STDC_NO_THREADS__
or per What is the value of an undefined constant used in #if?to
或 per #if 中使用的未定义常量的值是多少?到
#if __STDC_NO_THREADS__
This matches OP's code, so I would have expected that to work with a compliant C11 compiler.
这与 OP 的代码相匹配,所以我希望它能与兼容的 C11 编译器一起使用。
Yet it looks like OP has a solutionper @Kevin. That may be a false solution as __STDC_NO_THREADS
looks like a typo (missing trailing __
).
然而,看起来 OP每个@Kevin都有一个解决方案。这可能是一个错误的解决方案, 看起来像一个错字(缺少尾随)。__STDC_NO_THREADS
__
#if !defined(__STDC_NO_THREADS) || __STDC_NO_THREADS__
回答by Marshall Clow
In C++11, you want to #include <thread>
, not threads.h
在 C++11 中,你想要#include <thread>
,而不是threads.h
#include <iostream>
#include <thread>
void fun() { std::cout << "fun!" << std::endl; }
int main() {
std::thread t ( fun );
t.join ();
return 0;
}