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 is not a header-only library. Please build the library and then add it. Simple in gcc:
gcc myapp.cpp -omyapp -lboost_date_time
(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.)
I think the compiler is complaining about the inclusion of boost lib.
In order to use boost::gregorian(boost::date_time), you need to use bjam to build boost library and then link it against the FileSystem lib.
The reference of boost see click here.
EDIT: According to what you got above, the problem is that the library can't be found, mingw seems like don't know where it is. A re-installation of mingw maybe required or you can try to specify the specific path of the library.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With