【问题标题】:c++ -std=c++11 -stdlib=libc++ with boost.thread gives Segmentation fault: 11 on OSXc++ -std=c++11 -stdlib=libc++ with boost.thread给出Segmentation fault: 11 on OSX
【发布时间】:2013-04-29 09:02:49
【问题描述】:

尝试运行一些示例代码。
但是发生了意想不到的事情。
我想知道关于 boost.thread 与 libc++ 一起使用有什么已知的问题吗?


使用-std=c++11 或无选项编译的程序运行良好。

但是当我使用-stdlib=libc++-std=c++11 -stdlib=libc++ 编译时
输出是这样的:

in main
in thread
bash: line 1: 37501 Segmentation fault: 11  ./a.out

编译器:
Apple LLVM 版本 4.2 (clang-425.0.28)(基于 LLVM 3.2svn)
目标:x86_64-apple-darwin12.3.0
线程模型:posix

操作系统:Mac OS X 10.8.3

示例代码很简单:

#include "stdio.h"
#include <boost/thread/thread.hpp>

class callable
{
public:
    void operator()()
    {
        printf("in thread\n");
    }
};

int main()
{
    boost::thread t = boost::thread(callable());
    printf("in main\n");
    t.join();
    return 0;
}

【问题讨论】:

  • IIRC,我已经在某个地方看到过这个问题(因为我有类似的问题),但我不记得在哪里...... :(
  • @BЈовић 我只在终端中使用了c++
  • @soon 谢谢你的建议。会试试的。
  • 您需要确保 boost 也配置了 c++11 标志。顺便说一句,除非您正在寻找中断点或类似的东西,否则为什么不使用 std::thread ?
  • @dirvine 你是对的。我用 c++11 再次编译了 boost。它运行良好。所以这只是我使用boost的错误。谢谢。

标签: c++ boost c++11 boost-thread libc++


【解决方案1】:

boost.thread 可能与 libstdc++ 相关联。 libstdc++ 和 libc++ 的 ABI 不兼容。不应在一个程序中同时使用它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多