使用boost :: gregorian :: from_string()的链接器错误

时间:2012-02-14 12:00:10

标签: c++ boost linker visual-studio-2005 boost-date-time

我使用了版本1.48的visual studio 2005。 我在尝试使用boost::gregorian::from_string()时收到链接器错误。

#include <string>
#define BOOST_DATE_TIME_SOURCE
#include <boost/date_time/gregorian/gregorian.hpp>
using namespace boost::gregorian;
using namespace std;

void testDate(){
string s("2000-01-10");
date d2 = from_string(s);

}

int main()
{
testDate();
return 0;

}

并获取链接器错误:

error LNK2019: unresolved external symbol "public: static class boost::shared_ptr<class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,unsigned short,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class 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@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@GU?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@G@std@@@2@@std@@@3@XZ) referenced in function "unsigned short __cdecl boost::date_time::month_str_to_ushort<class boost::gregorian::greg_month>(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??$month_str_to_ushort@Vgreg_month@gregorian@boost@@@date_time@boost@@YAGABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

为什么?

2 个答案:

答案 0 :(得分:0)

Boost.DateTime不是header-only library,因为您使用的是from_string;您需要先compile it from source,然后在项目中link against it

答案 1 :(得分:0)

日期时间库

  

boost_date_time-vc140-mt.lib

不在lib文件夹中。我已经用vcpakcgae管理器安装了它,并且可以正常工作。