boost::gregorian::date myDate ( boost::gregorian::day_clock::local_day());
std::string today = boost::gregorian::to_iso_string(myDate);
第一句,date前要加命名空間;
第二句,報錯:
/tmp/ccaSDZPD.o: In function `boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::ostream&)':
type_cast_test.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo[_ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo]+0x33):
undefined reference to `boost::gregorian::greg_month::as_short_string() const'
type_cast_test.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo[_ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo]+0x56): undefined
reference to `boost::gregorian::greg_month::as_long_string() const'
網上查到解決方法:
(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.)
g++
-o edv-urlaub-xml.exe "src\\xml.o" "src\\sql.o" "src\\header\\tinyxml2\\tinyxml2.o" "src\\config.o" "src\\Main.o" -lodbc32 -lcomctl32 -lboost_date_time c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find
-lboost_date_time
Can you tell me what I'm doing wrong? Getting really frustrated.
編譯加上-lboost_date_time,解決