【问题标题】:Boost undefined references [duplicate]提升未定义的引用[重复]
【发布时间】:2017-04-15 09:00:16
【问题描述】:

我正在尝试学习 boost 库,但我什至无法从他们的官方教程中编译一个简单的程序。

Ubuntu 16.04LTS,通过以下方式安装 boost:

sudo apt-get install libboost-all-dev

test.cpp:

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

int main()
{
    boost::asio::io_service io;
    boost::asio::deadline_timer t(io, boost::posix_time::seconds(5));
    t.wait();
    std::cout << "Hello, world!" << std::endl;

    return 0;
}

编译命令:

g++ -l boost_system test.cpp
/tmp/ccFqTvqW.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x11f): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x12b): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x137): undefined reference to `boost::system::system_category()'
/tmp/ccFqTvqW.o: In function `boost::system::error_code::error_code()':
test.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
/tmp/ccFqTvqW.o: In function `boost::asio::error::get_system_category()':
test.cpp:(.text._ZN5boost4asio5error19get_system_categoryEv[_ZN5boost4asio5error19get_system_categoryEv]+0x5): undefined reference to `boost::system::system_category()'
collect2: error: ld returned 1 exit status

【问题讨论】:

    标签: c++ ubuntu boost


    【解决方案1】:

    将这些标志添加到您的编译命令(g++ 或 clang):

    -lboost_system -lboost_filesystem
    

    【讨论】:

    • 在哪里可以了解我需要链接哪些库?还有为什么这不起作用? g++ -l boost_system -l boost_filesystem test.cpp 为什么要删除 l 和 boost_* 之间的空格?
    • @AranBins 谷歌一下!
    猜你喜欢
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 2017-04-02
    • 2015-10-18
    相关资源
    最近更新 更多