0

I get link error of a simple c++ program when using functions from boost date-time library, e.g. boost::gregorian::from_us_string

I have searched on the internet, saying that I need to link with boost at the system level.

On this post,How to link to boost date_time, it mentioned the installation on Linux system.

How should i install the boost date-time library on windows? I could not find a good post online on explaining how to compile the date-time library.

The boost library itself have been successfully compiled. I am using visual studio 2017/2019 for the c++ project on a windows 10 Dell computer.

The error message:

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)
1>C:\Users\C66669\YuXiang_work\FX_Option\NewFX\Debug\testFile.exe : fatal error LNK1120: 1 unresolved externals
Luigi Ballabio
  • 4,128
  • 21
  • 29
XYZ
  • 352
  • 5
  • 19
  • There is no need to install anything. You need to link that library by adjusting linker settings accordingly. "installation" on Linux typically implies dumping stuff into some locations that were hardcoded inside of compiler; exceptionally poor practice. – user7860670 Aug 29 '19 at 11:46
  • Unless you have explicitly disabled it with preprocessor definitions boost should automatically add links to required libraries, you then just need to add the directory containing the boost libs to the linker directories – Alan Birtles Aug 29 '19 at 12:05
  • I did not get it,if I include the following code I have errors: boost::gregorian::date boost_date = boost::gregorian::from_us_string(cell); I am sure that I have included the header files. Also, I used other functionality of boost. If I do not use the the boost::gregorian, no compilation error happens. I am sure that I set the path in the link directory correctly. Any idea?@VVT, @Alan Birtles – XYZ Aug 29 '19 at 12:11
  • show your build settings i.e. a [mre] – Alan Birtles Aug 29 '19 at 12:51
  • Hi @AlanBirtles, thanks for the comment. Indeed this should not be a link error. And the boost:gregorian library could be used. The error happened because the format of the string is inconsistent with what expected from boost::gregorian::from_us_string. But it is weird to have a link error when it is actually a format error with the string. – XYZ Aug 29 '19 at 14:12
  • If you have installed or built the `boost` libraries then see this [answer](https://stackoverflow.com/questions/45974108/how-to-add-boost-library-1-65-or-1-64-to-visual-studio-2017-project/45975278#45975278) to add the libraries to Visual Studio's library path. – kenba Aug 30 '19 at 06:58

0 Answers0