linux下boost遇到的坑

boost错误

由于项目需要便开始学习boost中的asio库,但由于编译出现不知名的错,便停顿了,后来查了好多资料在发现是由于要支持线程,所以在编译时要加入线程链接库,具体如下
源代码:

#include <iostream>
#include <boost/asio.hpp>


int main()
{
  boost::asio::io_context io;

  boost::asio::steady_timer t(io, boost::asio::chrono::seconds(5));
  t.wait();

  std::cout << "Hello, world!" << std::endl;

  return 0;
}

编译时的错误情况:
在这里插入图片描述正确做法的编译命令:
g++ main.cpp -lpthread -o main

如果是想在QtCreator中使用的话,必须在.pro中添加链接
CONFIG += thread

发布了17 篇原创文章 · 获赞 3 · 访问量 416

猜你喜欢

转载自blog.csdn.net/qq_41172631/article/details/103941325