C++ 11 线程与 clang

2024-01-23

我想学习使用 C++11 线程来加速我的语言的编译(是的,我正在构建一个编译器:x)。我尝试的第一个示例在 clang (3.3 SVN) 中抛出了几个错误。它在 GCC (4.6.3) 下编译得很好。

我从 llvm.org 的 SVN 下载了 clang 和 libc++。 clang 使用 GCC (4.6.3) 编译,libc++ 使用 clang 编译。两个 makefile 都是使用 CMake 生成的。

对于 clang,我遵循了这个指南:http://llvm.org/docs/GettingStarted.html#checkout http://llvm.org/docs/GettingStarted.html#checkout

对于 libc++ 我遵循了这个指南:http://libcxx.llvm.org/ http://libcxx.llvm.org/

我要编译的代码段(foobar.cpp):

#include <iostream>
#include <thread>

using namespace std;

int main(void) {
    thread t1([](void)->void {
        cout << "foobar" << endl;
    });
}

它编译得很好clang --std=c++0x -stdlib=libc++ -lpthread foobar.cpp但我收到很多链接器错误:

/tmp/foobar-59W5DR.o: In function `main':
foobar.cpp:(.text+0x21): undefined reference to `std::__1::thread::~thread()'
/tmp/foobar-59W5DR.o: In function `_ZNSt3__16threadC2IZ4mainE3$_0JEvEEOT_DpOT0_':
foobar.cpp:(.text+0x5c): undefined reference to `operator new(unsigned long)'
foobar.cpp:(.text+0x186): undefined reference to `operator delete(void*)'
foobar.cpp:(.text+0x19b): undefined reference to `std::__1::__throw_system_error(int, char const*)'
/tmp/foobar-59W5DR.o: In function `_ZNSt3__114__thread_proxyINS_5tupleIJZ4mainE3$_0EEEEEPvS4_':
foobar.cpp:(.text+0x200): undefined reference to `std::__1::__thread_local_data()'
foobar.cpp:(.text+0x211): undefined reference to `operator new(unsigned long)'
foobar.cpp:(.text+0x23b): undefined reference to `std::__1::__thread_struct::__thread_struct()'
foobar.cpp:(.text+0x31b): undefined reference to `operator delete(void*)'
/tmp/foobar-59W5DR.o: In function `_ZNSt3__110unique_ptrINS_5tupleIJZ4mainE3$_0EEENS_14default_deleteIS3_EEED2Ev':
foobar.cpp:(.text+0x3dd): undefined reference to `operator delete(void*)'
/tmp/foobar-59W5DR.o: In function `main::$_0::operator()() const':
foobar.cpp:(.text+0x3fc): undefined reference to `std::__1::cout'
/tmp/foobar-59W5DR.o: In function `_ZNSt3__110unique_ptrINS_5tupleIJZ4mainE3$_0EEENS_14default_deleteIS3_EEEC2EPS3_':
foobar.cpp:(.text+0x4e9): undefined reference to `std::terminate()'
/tmp/foobar-59W5DR.o: In function `std::__1::__thread_specific_ptr<std::__1::__thread_struct>::reset(std::__1::__thread_struct*)':
foobar.cpp:(.text._ZNSt3__121__thread_specific_ptrINS_15__thread_structEE5resetEPS1_[_ZNSt3__121__thread_specific_ptrINS_15__thread_structEE5resetEPS1_]+0x57): undefined reference to `std::__1::__thread_struct::~__thread_struct()'
foobar.cpp:(.text._ZNSt3__121__thread_specific_ptrINS_15__thread_structEE5resetEPS1_[_ZNSt3__121__thread_specific_ptrINS_15__thread_structEE5resetEPS1_]+0x60): undefined reference to `operator delete(void*)'
/tmp/foobar-59W5DR.o: In function `std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::operator<< <std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, char const*)':
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x28): undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::sentry(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x1ec): undefined reference to `std::__1::ios_base::getloc() const'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x1fe): undefined reference to `std::__1::ctype<char>::id'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x206): undefined reference to `std::__1::locale::use_facet(std::__1::locale::id&) const'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x272): undefined reference to `std::__1::locale::~locale()'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x294): undefined reference to `std::__1::locale::~locale()'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x378): undefined reference to `std::__1::ios_base::clear(unsigned int)'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x3d0): undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x3dc): undefined reference to `__cxa_begin_catch'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x3f9): undefined reference to `std::__1::ios_base::__set_badbit_and_consider_rethrow()'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x403): undefined reference to `__cxa_end_catch'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x424): undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::sentry::~sentry()'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x43d): undefined reference to `__cxa_end_catch'
foobar.cpp:(.text._ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc[_ZNSt3__1lsINS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKc]+0x466): undefined reference to `std::terminate()'
/tmp/foobar-59W5DR.o: In function `std::__1::basic_ostream<char, std::__1::char_traits<char> >& std::__1::endl<char, std::__1::char_traits<char> >(std::__1::basic_ostream<char, std::__1::char_traits<char> >&)':
foobar.cpp:(.text._ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_[_ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_]+0x38): undefined reference to `std::__1::ios_base::getloc() const'
foobar.cpp:(.text._ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_[_ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_]+0x49): undefined reference to `std::__1::ctype<char>::id'
foobar.cpp:(.text._ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_[_ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_]+0x55): undefined reference to `std::__1::locale::use_facet(std::__1::locale::id&) const'
foobar.cpp:(.text._ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_[_ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_]+0xac): undefined reference to `std::__1::locale::~locale()'
foobar.cpp:(.text._ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_[_ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_]+0xbe): undefined reference to `std::__1::locale::~locale()'
foobar.cpp:(.text._ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_[_ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_]+0xcd): undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::put(char)'
foobar.cpp:(.text._ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_[_ZNSt3__14endlIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_]+0xdd): undefined reference to `std::__1::basic_ostream<char, std::__1::char_traits<char> >::flush()'
/tmp/foobar-59W5DR.o: In function `std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char)':
foobar.cpp:(.text._ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_[_ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_]+0x215): undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(unsigned long, char)'
foobar.cpp:(.text._ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_[_ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_]+0x389): undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
foobar.cpp:(.text._ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_[_ZNSt3__116__pad_and_outputIcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_]+0x3a4): undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()'
/tmp/foobar-59W5DR.o:(.eh_frame+0x47): undefined reference to `__gxx_personality_v0'
clang-3: error: linker command failed with exit code 1 (use -v to see invocation)

下面是两个标准库下的标准搜索目录。 由于 'clang -Wp,-v -x c++ - -fsyntax-only' 我得到了这个:

I tried clang --std=c++11 -stdlib=libc++ -llibc++ -lpthread -o foobar foobar.cpp但是链接器又失败了,它没有找到libc++。我是否无法链接到 libc++ 或者是更困难的事情?


您正在使用 clang 为 C 而不是 C++ 进行编译。

  • 供C使用clang
  • 对于 C++ 使用clang++

The reason why clang didnt warn you is because you explicitly defined the standard.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++ 11 线程与 clang 的相关文章

随机推荐

  • Keras Conv2D 和输入通道

    Keras 层文档指定了卷积层的输入和输出大小 https keras io layers 卷积 https keras io layers convolutional 输入形状 samples channels rows cols 输出形
  • 如何将多个报告附加在一起?

    我有许多报告需要单独运行 也需要作为一组运行 我已经创建了这些报告 并希望我可以创建一个表单 在其中可以将 report1 report2 report3 等附加在一起 而无需创建不同的报告并制作所有这些报告的子报告 这可能吗 编辑 我在
  • Akka 在 Actor 之外进行日志记录

    我有一个 Akka Actor 打电话给MyObject foo MyObject不是演员 如何设置登录 使用 Actor 就很简单 因为我可以混合 Actor Logging 在 MyObject 中 我无权访问 context syst
  • 复制data.frame的每一行并指定每行的复制次数?

    我在 R 中编程 遇到以下问题 我有一个数据字符串 jb 它很长 这是它的一个简单版本 jb a b frequency jb expanded a b 5 3 2 5 3 5 7 1 5 3 9 1 40 5 7 12 4 5 9
  • 如何使用 YAML 配置文件使用对象参数实例化新对象?

    我试图使用配置文件来允许用户选择实现某些抽象类或接口的具体聚类算法 每种算法的先决条件输入可能略有不同 一个小的概念示例 KMedoids只需要拥有k由用户设置 SpectralClustering还需要k但还需要其他一些东西 例如Enum
  • 当绑定属性声明为接口与类类型时,WPF 绑定行为不同吗?

    这始于我认为与我的实施有关的奇怪行为ToString 我问了这个问题 当 ToString 具有协作对象时 为什么 WPF 数据绑定不显示文本 https stackoverflow com questions 2916068 why wo
  • 在CSS中创建一个自适应四边形梯形

    是否可以在 css 中创建图像形状 上周我在谷歌上搜索的次数比我愿意承认的还要多 但没有找到解决方案 我已经能够半复制它 但还没有解决所有要求 有边界 反应灵敏 适应内容高度 以厘米为单位 所以我无法控制文本量 在 IE9 中工作 它需要适
  • 如何更改 Eclipse 运行配置的工作目录?

    我有一个 Eclipse 运行配置 我想为其设置工作目录 我该怎么做呢 我浏览了运行配置的不同选项卡 包括 环境 选项卡 但没有看到任何明显的东西 这是开普勒 SR1 上的 参数选项卡
  • Apache CXF REST 分段上传,编码异常

    我想使用多部分表单数据上传文件 但 URLDecoder 出现问题 服务代码如下 POST Path document Consumes MediaType MULTIPART FORM DATA public Response store
  • 爆炸不适用于字符串内的多个逗号[关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我尝试在这里和谷歌中找到答案 但没有
  • 如何解决 IDLE 中的 ModuleNotFound 错误?

    我使用的是ubuntu 18 04 我首先从版本为 3 7 0 的终端安装了 Python 和 anaconda 并且还启动了 Jupyter Notebook 和 Spyder 然后我安装了 IDLE 其版本为 3 6 6 并且我当前正在
  • Cython 并行 prange - 线程局部性?

    我正在使用 prange 迭代这样的列表 from cython parallel import prange threadid cdef int tid cdef CythonElement tEl cdef int a b c elLi
  • tabindex 给出了它的焦点,但是在回车键上输入它不起作用

    当我用鼠标单击搜索图标时 它工作正常 但是当我使用选项卡并且焦点转到图标时 但当我输入 ENTER 关键字时 它不起作用 div class mobile header icon i class search i div 紧迫enter不触
  • Carrierwave:如果尺寸大于则缩放图像(有条件创建版本)

    仅当图像大于版本大小时 才可以使用载波创建版本 例如拇指 吗 Example version thumb if gt is thumbnable do process resize to fit gt 32 nil end protecte
  • 类型注释被推断的表达式类型覆盖

    在 Scala 编程语言中 假设我将使用更广泛的类型注释表达式并提供一个狭窄的值 我的程序将被拒绝 scala gt def x A A 8
  • 使用 HTML 和 CSS 剪辑图像

    我想在 144px x 144px div 元素中显示图像 图像总是大于 144px 所以我想缩放它们 我的意思是最小的一侧将接触 div 的边缘 从另一侧 与信箱相反 切掉一点 我怎样才能做到这一点并让它在 IE 等旧版浏览器上也能工作
  • 在 NodeJS Lambda 函数中列出 AWS.CognitoIdentityServiceProvider.listUsers 中的用户及其组?

    因此 我需要在客户端的自定义管理屏幕中显示用户列表及其各个组 我正在返回结果AWS CognitoIdentityServiceProvider listUsers在 Lambda 函数中 这可以很好地列出用户 但我不确定为每个用户获取组并
  • 按行名称连接多个表[重复]

    这个问题在这里已经有答案了 我想按行名称合并多个表 这些表的行数不同 并且它们具有唯一行和共享行 这些行都应该出现在输出中 如果可能的话我想解决这个问题awk 但我也对其他解决方案感到满意 表1 tab a 5 b 5 d 9 表2 tab
  • C++:成员指针已初始化?

    代码示例应该解释一下 class A B pB C pC D d public A int i int j d j pC new C i abc note pB is not initialised e g pB NULL 显然 pB 应该
  • C++ 11 线程与 clang

    我想学习使用 C 11 线程来加速我的语言的编译 是的 我正在构建一个编译器 x 我尝试的第一个示例在 clang 3 3 SVN 中抛出了几个错误 它在 GCC 4 6 3 下编译得很好 我从 llvm org 的 SVN 下载了 cla