gpt4 book ai didi

c++ - 对 boost::gregorian::greg_month::as_short_string() const 的 undefined reference

转载 作者:IT老高 更新时间:2023-10-28 21:38:59 28 4
gpt4 key购买 nike

这被问了好几次,但我不知道我做错了什么。我正在尝试将当前日期减去 7。这是主要的:

#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;
}

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

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'

有人可以帮忙吗?我以为我包含了必要的文件..

最佳答案

Boost date_time 不是一个只有头文件的库。请构建库,然后添加它。在 gcc 中很简单:

gcc myapp.cpp -omyapp -lboost_date_time

(小心!由于内联,这个库偷偷地似乎在优化级别 -O2 和更高级别上作为仅 header 库工作;但它会失败当您使用编译器的内联器不那么激进的较低优化级别时链接。)

关于c++ - 对 boost::gregorian::greg_month::as_short_string() const 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17477177/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com