您的位置:首页 > 其它

Boost::Date_time库和time_from_string()函数的使用

2012-10-14 21:22 441 查看
  前一段时间,想在Qt中使用Stlport和Boost,结果发现了一个有些奇怪的现象,使用Boost::Data_Time库时会有链接错误,但是用其他的库就没有问题,比如foreach,fromat,string_algo。用qmake生成VC项目后和之前使用Boost::Date_Time的VC项目比较,发现差别在“将wchar_t视为内置类型”,当时用的Qt SDK是直接下载的编译好的,不支持wchar_t,为此特意下载了Qt的源码,自己修改配置然后编译,现问题已解决。在Boost中文文档上看到这段话,也证明问题确实是处在是否支持
wchar_t。截图如下:




不过我在用Stlport编译Boost时Date_Time并没有出问题,现在的Stlport应该是默认支持wchar_t。

  在Boost::Date_Time的使用过程中还发现了一个问题,就是在用到time_from_string()时会报链接错误,如下:

错误    1    error LNK2019: 无法解析的外部符号 "public: static class boost::shared_ptr<class stlpd_std::map<class stlpd_std::basic_string<char,class stlpd_std::char_traits<char>,class stlpd_std::allocator<char> >,unsigned short,struct stlpd_std::less<class stlpd_std::basic_string<char,class stlpd_std::char_traits<char>,class stlpd_std::allocator<char> > >,class stlpd_std::allocator<struct stlpd_std::pair<class stlpd_std::basic_string<char,class stlpd_std::char_traits<char>,class stlpd_std::allocator<char> > const ,unsigned short> > > > __cdecl boost::gregorian::greg_month::get_month_map_ptr(void)" (?get_month_map_ptr@greg_month@gregorian@boost@@SA?AV?$shared_ptr@V?$map@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@GU?$less@V?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@G@stlpd_std@@@2@@stlpd_std@@@3@XZ),该符号在函数 "unsigned short __cdecl boost::date_time::month_str_to_ushort<class boost::gregorian::greg_month>(class stlpd_std::basic_string<char,class stlpd_std::char_traits<char>,class stlpd_std::allocator<char> > const &)" (??$month_str_to_ushort@Vgreg_month@gregorian@boost@@@date_time@boost@@YAGABV?$basic_string@DV?$char_traits@D@stlpd_std@@V?$allocator@D@2@@stlpd_std@@@Z) 中被引用


在网上找解决办法时,都是说不能只包含头文件,还要链接相应的库,实际上不是没有链接库产生的问题。

  在%BOOST%/lib/date_time/src/gregorian目录下,有greg_month.cpp和greg_names.hpp两个文件,前面无法解析的get_month_map_ptr(void)就定义在greg_month.cpp中,而greg_month.cpp又依赖greg_names.hpp,只需将greg_month.cpp加入项目,greg_names.hpp放在项目目录下即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: