【发布时间】: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++