增加未定义的引用 [英] Boost undefined references

查看:76
本文介绍了增加未定义的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习Boost库,甚至从他们的官方教程中编译一个简单的程序也遇到了麻烦.

I'm trying to learn the boost library and I'm having trouble even compiling a simple program from their official tutorials.

Ubuntu 16.04LTS,通过以下方式安装了增强功能:

Ubuntu 16.04LTS, installed boost via:

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

推荐答案

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

Add these flags to your compilation command (g++ or clang):

-lboost_system -lboost_filesystem

这篇关于增加未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆