为什么这个简单的c++11线程示例在使用clang 3.2编译时失败?
Why does this simple c++11 threading-example fail, when compiled with clang 3.2?
我不知道我做错了什么。这个很短的程序:
#include <iostream>
#include <string>
#include <atomic>
#include <thread>
using namespace std;
int
main(int argc, char ** argv)
{
thread foo( []() {
cout << "Hello World" << endl;
return 0;
} );
foo.join();
return 0;
}
使用gcc (4.7.2)
编译时效果很好:
$ g++ -ggdb -std=c++11 -pthread -o clang_thread_test clang_thread_test.cpp
$ ./clang_thread_test
Hello World
但是,当使用clang (3.2; x86_64-pc-linux-gnu; thread model: posix)
编译时,它执行失败:
$ clang++ -ggdb -std=c++11 -pthread -o clang_thread_test clang_thread_test.cpp
$ ./clang_thread_test
pure virtual method called
terminate called without an active exception
Aborted
有一个已知的原因吗?我发现的唯一的事情是与缺失的-pthread switch
或未使用的libc++
有关。据我所知,后者只适用于苹果系统。
确认此操作有效:
clang++ --std=c++11 -pthread -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 -D__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53841 修复:
linux error: no matching constructor for initialization of 'duration'
使用建议修复
- const chrono::nanoseconds __delta = __atime - __c_entry;
- const __clock_t::time_point __s_atime = __s_entry
+ __delta; + const auto __delta = __atime - __c_entry;
+ const auto __s_atime = __s_entry
+ __delta; in file condition_variable
相关文章:
- 通过自制软件(macOS)安装的clang++:编译错误
- 在使用 Clang 编译 DLL 时指定 DEF 文件
- constexpr 使用 clang 编译 TensorFlow 时出错
- clang编译的程序在std::any_cast期间抛出std::bad_any_cast
- 使用 Android NDK 使用 clang++ 编译C++代码时对"_Unwind_Resume"的未定义引用
- 为什么这段代码无法使用 gcc 4.8.5 编译,而使用 clang 编译正常
- 向 cppFlags 添加"-O0"无法禁用 Android Studio 中的 clang 编译优化
- C++汇编代码分析(使用 clang 编译)
- 为什么以下代码不使用GCC编译,而是用Clang编译罚款
- clang编译错误与static_assert和boost :: hana有关
- clang 编译模板类,并在标题中实现
- 在Windows上使用clang编译CUDA时的重新定义
- 如何在OSX上为clang编译 #include < 实验/任意>
- constexpr 唯一 ID,使用 clang 编译,但不使用 GCC 编译
- 是否可以仅在Windows上使用Clang编译C ++
- 当我用clang编译代码时,GCOV会出现内存错误
- 在MacOS上使用gcc-8而不是clang编译Qt5
- 如何使用 clang 编译特殊的数学函数
- 使用 gcc 编译和使用 clang 编译代码时未定义的引用
- 使用clang编译时regex-segfault,可能存在编译器错误