未定义的引用boost :: gregorian :: greg_month :: as_short_string()const [英] undefined reference to boost::gregorian::greg_month::as_short_string() const

查看:2795
本文介绍了未定义的引用boost :: gregorian :: 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'

任何人都可以帮助?我认为我包含了必要的文件..

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

推荐答案

Boost 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.)

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

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