在xubuntu中对boost :: program_options的未定义引用 [英] undefined reference to boost::program_options in xubuntu

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

问题描述

我有这个文件

#include <boost/program_options.hpp>
namespace po = boost::program_options;

#include <iostream>
using namespace std;

int main(int ac, char* av[])
{
    try {

    po::options_description desc("Allowed options");
        desc.add_options()
            ("help", "produce help message")
        ;

    }
    catch(exception& e) {
        cerr << "error: " << e.what() << "\n";
        return 1;
    }
    catch(...) {
        cerr << "Exception of unknown type!\n";
    }

    return 0;
}

现在我正在尝试像这样编译:

Now I am trying to compile like this:

g ++ -I/usr/include/boost/-I/usr/include/boost/program_options main.cpp -L/usr/lib/x86_64-linux-gnu/-lboost_program_options

g++ -I /usr/include/boost/ -I /usr/include/boost/program_options main.cpp -L /usr/lib/x86_64-linux-gnu/ -lboost_program_options

我收到了这个

未定义的参考 `boost :: program_options :: options_description :: options_description(std :: __ cxx11 :: basic_string,std :: allocator> const& ;, unsigned int, unsigned int)'

undefined reference to `boost::program_options::options_description::options_description(std::__cxx11::basic_string, std::allocator > const&, unsigned int, unsigned int)'

我不知道为什么它失败,库在那里,头文件也是如此.怎么了?我正在使用Boost 1.55.0

I don't know why it is failing, the library is there and the header file too. What goes wrong? I am using boost 1.55.0

administrator@administrator-VirtualBox:~/l/b$ sudo updatedb
administrator@administrator-VirtualBox:~/l/b$ locate libboost_program_options
/usr/lib/x86_64-linux-gnu/libboost_program_options.a
/usr/lib/x86_64-linux-gnu/libboost_program_options.so
/usr/lib/x86_64-linux-gnu/libboost_program_options.so.1.55.0

推荐答案

看起来boost是用C ++ 11 std::basic_string编译的.

Looks like boost was compiled with pre-C++11 std::basic_string, whereas your code is compiled with C++11 std::basic_string.

尝试使用-D_GLIBCXX_USE_CXX11_ABI=0编译器命令行选项重新编译代码.参见 GCC5和C ++ 11 ABI 以获得更多详细信息:

Try re-compiling your code with -D_GLIBCXX_USE_CXX11_ABI=0 compiler command line option. See GCC5 and the C++11 ABI for more details:

在大多数情况下,由于链接器的错误抱怨涉及__cxx11的未解析符号,因此在需要此标志时很明显.

In most cases, it will be obvious when this flag is needed because of errors from the linker complaining about unresolved symbols involving __cxx11.

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

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