本文介绍了未定义的引用,以提高::阳历:: greg_month :: as_short_string()const的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问了几次,但是我不知道我做错了事情。我试图让7。这里减去当前日期是最主要的:

This was asked several times however I don't know what I'm doing wrong. I'm trying to get the current date subtracted by 7. Here's the Main:

#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/date_formatting.hpp>
#include <boost/date_time/gregorian/greg_month.hpp>


using namespace std;
using namespace boost::gregorian;

int main(int argc, char **argv) {

    time_t rawtime;
    struct tm *timeinfo;

    time (&rawtime);
    timeinfo = localtime (&rawtime);

    date cdate(timeinfo->tm_year+1900, timeinfo->tm_mon+1, timeinfo->tm_mday);
    cdate += date_duration(-7);

    string date = to_iso_string(cdate);
    cout << date << endl;
    return 0;
}

当我尝试编译它,我收到以下错误。

When I try to compile it I get the following error.

E:/include/boost/date_time/date_formatting.hpp:44: undefined reference to `boost::gregorian::greg_month::as_short_string() const'
E:/include/boost/date_time/date_formatting.hpp:49: undefined reference to `boost::gregorian::greg_month::as_long_string() const'

谁能帮助?我以为我包括neccessary文件。

Can anyone help? I thought I included the neccessary files..

推荐答案

升压DATE_TIME不是一个只有头库。请构建库,然后添加它。在简单的gcc:

Boost date_time is not a header-only library. Please build the library and then add it. Simple in gcc:

gcc myapp.cpp -omyapp -lboost_date_time

(注意!这个库悄悄的出现的为在优化级别 -O2 高的只有头库和工作中,由于内联;但它会失败,当你使用较低的优化级别,其中编译器的内联是不是咄咄逼人链接)

(Be careful! This library sneakily appears to work as a header-only library at optimization levels -O2 and higher, due to inlining; but it will fail to link when you use lower optimization levels where the compiler's inliner isn't as aggressive.)

这篇关于未定义的引用,以提高::阳历:: greg_month :: as_short_string()const的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:04