<boost/program_options/options_description.hpp>有什么问题?

-1 c++ boost

我需要帮助,我一直在同一台计算机上执行此操作,这意味着我已经安装了boost库,并且基于之前的代码,但这次它给了我错误:/tmp/ccpAYzPw.o:在函数`main' :

reading_data.cpp:(.text+0x356): undefined reference to `boost::program_options::options_description::m_default_line_length'
reading_data.cpp:(.text+0x361): undefined reference to `boost::program_options::options_description::m_default_line_length'
reading_data.cpp:(.text+0x3a6): undefined reference to `boost::program_options::options_description::options_description(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned int, unsigned int)'
reading_data.cpp:(.text+0x3d3): undefined reference to `boost::program_options::options_description::add_options()'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'reading_data' failed
Run Code Online (Sandbox Code Playgroud)

我花了差不多2个小时看看发生了什么?但我无法理解为什么,所以我需要你的帮助.

这是我的代码,非常感谢你.

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>      // std::ifstream
#include <boost/program_options.hpp>

int main ()
{
    boost::program_options::options_description desc("Allowed options");

    desc.add_options()
            ("sign"  , program_options::value<string>()  -> default_value("gbm")    ,"name of the input")
            ("week"  , program_options::value<double>()  -> default_value(1930)     ,"number of the week")
            ("day"   , program_options::value<double>()  -> default_value(0)        ,"number of the day in within the week")
            ("hour"  , program_options::value<double>()  -> default_value(0)        ,"time in hour")
            ("minute", program_options::value<double>()  -> default_value(0)        ,"time in minute")
            ("second", program_options::value<double>()  -> default_value(0)        ,"time in second")
            ;

    cout << "Done!" << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Vit*_*meo 7

您似乎没有链接库.boost::program_options 不是标头,所以你必须明确链接它:

-lboost_program_options
Run Code Online (Sandbox Code Playgroud)