zoukankan      html  css  js  c++  java
  • Boost::Date_time库和time_from_string()函数的使用

      前一段时间,想在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放在项目目录下即可。

  • 相关阅读:
    js数组与字符串的相互转换
    JS怎么把字符串数组转换成整型数组
    element-UI的操作步骤steps每一项添加事件,比如click,hover
    element-UI ,Table组件实现拖拽效果
    修改本机域名localhost为任意你想要的名称
    el-tree 设置目录树中的某个节点为高亮状态
    Akka-CQRS(2)- 安装部署cassandra cluster,ubuntu-16.04.1-LTS and MacOS mojave
    Akka-CQRS(1)- Write-side, Persisting event sources:CQRS存写端操作方式
    Akka-CQRS(0)- 基于akka-cluster的读写分离框架,构建gRPC移动应用后端架构
    Akka-Cluster(6)- Cluster-Sharding:集群分片,分布式交互程序核心方式
  • 原文地址:https://www.cnblogs.com/mian/p/2723394.html
Copyright © 2011-2022 走看看