在Ubuntu上如何使用Boost库编译C++代码?

17
#include <iostream>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

我使用了上面显示的标头。 在Boost官方网站上找不到帮助。


1
你需要展示你的尝试失败了--你是否遇到了未声明的函数;你是否缺少一些头文件,或者是否存在链接错误--一些boost函数需要链接到共享库。 - Vincent Marchetti
1个回答

27

假设您的代码没有错误,您需要链接正确的boost库:你已经引用了boost_thread、boost_system和boost_date_time库,因此

#include <iostream>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
int main()
{
}

使用以下命令编译此程序:

g++ -o test test.cc -lboost_system -lboost_date_time -lboost_thread

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接