参考博客:https://blog.csdn.net/weixin_40885370/article/details/80823767
windows 使用qtcreater编译boost 库命令;
bjam install stage --toolset=gcc --stagedir="./lib" link=static runtime-link=static threading=multi debug release
qtcreater添加头文件目录;
INCLUDEPATH += C:/boost_1_60_0/boost_1_60_0
qtcreater添加静态库;
LIBS += C:/boost_1_60_0/boost_1_60_0/stage/lib/libboost_system-mgw53-mt-sd-1_60.a
LIBS += C:/boost_1_60_0/boost_1_60_0/stage/lib/libboost_thread-mgw53-mt-sd-1_60.a
#include<boost/thread.hpp>
#include<boost/bind.hpp>
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
using namespace boost;
boost::shared_ptr<boost::thread> t = nullptr;
void hello()
{
while(1){
qDebug() << "Hello" << "world!";
boost::this_thread::sleep(boost::posix_time::milliseconds(5000));
}
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
t= static_cast<boost::shared_ptr<boost::thread> >(new boost::thread(hello));
}
MainWindow::~MainWindow()
{
delete ui;
}