【问题标题】:Application terminates on start when including <boost/thread>包含 <boost/thread> 时应用程序在启动时终止
【发布时间】:2018-04-23 03:01:12
【问题描述】:

在下面的简单代码中,如果我包含boost线程库,程序在执行时终止,甚至没有到达main函数。

一切正常编译,0 个警告,0 个错误。

我的环境:

  • Eclipse 开普勒
  • boost_1_65_1
  • GCC 6.3.0
  • Mingw(不知道版本,我在 sourceforge 上有当前版本)
  • 在项目/C/C++ 构建/设置中
    • GCC C++ 编译器/包括:c\boost\boost_1_65_1
    • MinGW C++ 链接器/库:
      • 库搜索路径:C:\boost\boost_1_65_1\stage\lib
      • 库:llibboost_thread-mgw63-mt-1_65_1、libboost_system-mgw63-mt-1_65_1、libboost_chrono-mgw63-1_65_1

代码:

#include <iostream>
#include <boost/thread/thread.hpp>
int main(int argc, char* argv[])
{
std::cout << "StackUnderFlow" << std::endl;
return 0;
}

我不知道问题的根源是什么,是吗:

  • 我构建 Boost/Thread 的方式
  • 项目的配置方式
  • ?

gdb 跟踪显示此错误:

058,965 25^error,msg="During startup program exited with code 0xc0000135."
058,965 (gdb) 
058,965 26^error,msg="Can not fetch data now."
058,965 (gdb) 
058,980 27-gdb-exit
058,980 28-data-evaluate-expression $_exitcode
058,996 27^exit

【问题讨论】:

  • “执行时终止”是什么意思?你至少收到一条消息吗?
  • -pthread -lpthread 添加到您的编译/链接选项中
  • 我的 Main 第一行的断点没有命中,也没有输出到控制台。另外,我确实在 MinGW 安装管理器中安装了所有线程库。

标签: c++ boost boost-thread


【解决方案1】:

代码需要编译和链接-pthread选项。 -lpthread 链接器选项不足且不必要。

【讨论】:

    猜你喜欢
    • 2017-03-05
    • 2016-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 2011-07-29
    相关资源
    最近更新 更多