我想在Ubuntu 14.04上的QT創建器中使用C++ Boost庫,嘗試了很多方法後,仍然出現錯誤。如何在Ubuntu的QT創建器中使用Boost庫14.04
我安裝使用Boost庫:
sudo apt-get install libboost-all-dev
Boost庫安裝目錄:
/usr/include/boost
這裏是我的main.cpp
#include <QCoreApplication>
#include<iostream>
#include <boost/asio.hpp>
#include <boost/asio/steady_timer.hpp>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
boost::asio::steady_timer timer_;
timer_.expires_from_now(1000);
return a.exec();
}
任何我。 pro檔案:
QT += core
QT -= gui
CONFIG += c++11
TARGET = test_boost_lib_in_QT
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += /usr/include/boost
LIBS += -L/usr/include/boost -lboost_system
LIBS += -L/usr/include/boost -lboost_chrono
LIBS += -L/usr/include/boost -lboost_thread
LIBS += -L/usr/include/boost -lboost_timer
的編譯錯誤是:
/home/ndn-experiment/Desktop/test_boost_lib_in_QT/main.cpp:13: error: no matching function for call to 'boost::asio::basic_waitable_timer<std::chrono::_V2::steady_clock>::basic_waitable_timer()'
boost::asio::steady_timer timer_;
^
/home/ndn-experiment/Desktop/test_boost_lib_in_QT/main.cpp:14: error: no matching function for call to 'boost::asio::basic_waitable_timer<std::chrono::_V2::steady_clock>::expires_from_now(int)'
timer_.expires_from_now(1000);
^
我應該怎麼做(用 「CTRL + B」 我直接從QT編譯)?
首先 - asio需要一個io_service。 steady_timer沒有默認構造函數。 second - expires_from_now要求持續時間作爲參數。 int參數沒有重載。 – stefan