用到boost時間,編譯報錯

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 -O2and 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,解決

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章