如何使用 boost lib 编译 C++ 代码?在 Ubuntu 上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5891339/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to compile c++ code with boost lib? on Ubuntu
提问by Don Lun
#include <iostream>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
I used headers shown above. Cannot find help on Boost Official website.
我使用了上面显示的标题。无法在 Boost 官方网站上找到帮助。
回答by Cubbi
Assuming no errors in your code, you need to link the correct boost libraries: boost_thread, boost_system, and boost_date_time are the ones you've referenced, so
假设您的代码中没有错误,您需要链接正确的 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()
{
}
This program compiles with the following command:
该程序使用以下命令编译:
g++ -o test test.cc -lboost_system -lboost_date_time -lboost_thread