请看一下这个简单的 C++
程序:
#include <iostream>
#include <thread>
void thread_test()
{
std::cout << "Thread test\n";
}
int main(int argc, const char * argv[])
{
std::thread t(thread_test);
t.join();
return 0;
}
我正在尝试在 macOS Sierra 上使用 Xcode 编译它。它不编译。它说 'thread' file not found
。
在build设置中,我为 C++ 标准库
使用了 libstdc++(GNU C++ 标准库)
选项。如果我将此设置切换为 libc++(支持 C++11 的 LLVM C++ 标准库)
那么没问题,它可以编译。但我的目标是通过使用 libstdc++
而不是 libc++
以某种方式编译它。有可能吗?你能给我一些建议吗?
最佳答案
Xcode 自带的libstdc++ 版本很旧,而且不包含thread
。 macOS 上的 pthreads 缺少一些超时函数(例如 pthread_mutex_timedlock()
)。
您不能在 macOS 上同时使用 std::thread
和 Xcode 提供的 libstdc++。您必须切换到 libc++ 或使用不同的库 boost::thread
都可以。 TinyThread++也是将在 macOS 下使用 libstdc++ 工作的替代方案。
关于c++ - libstdc++ 在 Mac 上找不到线程文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46794948/