libboost_timer-vc141-mt-gd-1_64.lib(cpu_timer.obj) : error LNK2019: unresolved external

Hi,
I hope it is ok to post here what I believe is a bug in boost 1.64.0 or Visual Studio 2017.

In a program I make use of boost timer library, and when I compile (in 64 bits) I get the following error:


libboost_timer-vc141-mt-gd-1_64.lib(cpu_timer.obj) : error LNK2019: unresolved external symbol "public: static class boost::chrono::time_point<class boost::chrono::steady_clock,class boost::chrono::duration<__int64,class boost::ratio<1,1000000000> > > __cdecl boost::chrono::steady_clock::now(void)" (?now@steady_clock@chrono@boost@@SA?AV?$time_point@Vsteady_clock@chrono@boost@@V?$duration@_JV?$ratio@$00$0DLJKMKAA@@boost@@@23@@23@XZ) referenced in function "void __cdecl `anonymous namespace'::get_cpu_times(struct boost::timer::cpu_times &)" (?get_cpu_times@?A0x4cf65ba4@@YAXAEAUcpu_times@timer@boost@@@Z)


Looking at cpu_timer.cpp and the function in an unnamed namespace in it, called get_cpu_times, I find the culprit:

1
2
3
4
5
6
void get_cpu_times(boost::timer::cpu_times& current)
  {
    boost::chrono::duration<boost::int64_t, boost::nano>
      x (boost::chrono::high_resolution_clock::now().time_since_epoch());
   // .....
}


The thing here is that the now() member of high_resolution_clock returns a time_point, like this:

 
boost::chrono::steady_clock::now(void) => (returns) boost::chrono::time_point<boost::chrono::steady_clock, boost::chrono::duration<__int64, boost::ratio<1,1'000'000'000>> 


This return appears to not be created anywhere (I don't know, just my opinion), hence the unresolved external.
I tried to fix this several ways and the simplest one was to just #include a boost file as below:

 
#include <boost/chrono/chrono.hpp> 


And, it works!!
Why? I am not sure at all!!

Any ideas?

Regards,
Juan Dent


Does the same happen on a standard-conforming C++ implementation of std::chrono?
Last edited on
But I am not using std::chrono??
Also, the big concern is: why does adding an include fix the problem?

Also, as far as I know, Microsoft's Visual Studio 2017 provides a standard conforming C++ implementation of std::chronology...

Regards,
Juan Dent
Last edited on
> #include <boost/chrono/chrono.hpp>
> And, it works!!

>> why does adding an include fix the problem?

May have something to do with indirectly including boost/chrono/config.hpp
which defines a bunch of preprocessor symbols and then includes boost/config/auto_link.hpp
Which has this comment at the top:
1
2
3
4
5
6
/*
  *   LOCATION:    see http://www.boost.org for most recent version.
  *   FILE         auto_link.hpp
  *   VERSION      see <boost/version.hpp>
  *   DESCRIPTION: Automatic library inclusion for Borland/Microsoft compilers.
  */


Boost Chrono is not 'header-only', have you tried explicitly linking with the library?
Thanks JLBorges once again!!
Your insight is impressive!
I am going to try to link explicitly and will let you know but I can't do it until tuesday.

But everything you said makes all the sense in the world so I am sure it works.

Again, thanks

Juan Dent
Hi JLBorges,

I tried to explicitly link the library but without the #include the error is the same - actually it makes sense because the linker error mentions the library (so it was linking the library since the start). See, the error message was:


1>libboost_timer-vc141-mt-gd-1_64.lib(cpu_timer.obj) : error LNK2019: unresolved external symbol "public: static class boost::chrono::time_point<class boost::chrono::steady_clock,class boost::chrono::duration<__int64,class boost::ratio<1,1000000000> > > __cdecl boost::chrono::steady_clock::now(void)" (?now@steady_clock@chrono@boost@@SA?AV?$time_point@Vsteady_clock@chrono@boost@@V?$duration@_JV?$ratio@$00$0DLJKMKAA@@boost@@@23@@23@XZ) referenced in function "void __cdecl `anonymous namespace'::get_cpu_times(struct boost::timer::cpu_times &)" (?get_cpu_times@?A0x4cf65ba4@@YAXAEAUcpu_times@timer@boost@@@Z)


So, this library itself must have a link dependency that is added automatically when we:

 
#include <boost/chrono/chrono.hpp>  


is there a map of link dependencies between the libraries of boost 1.64?


Best regards,
Juan Dent
> I tried to explicitly link the library but without the #include the error is the same

Link explicitly with the appropriate version (debug/non-debug x single/multi-threaded) of the boost chrono library.
Hi JLBorges,

I was linking to the appropriate version... but your suggestion made me look into auto_link.hpp and I learned more about the encoding of boost libraries for Microsoft compilers so Thanks!

Also, my hunch that the problem was another library missing was correct. I found the missing library by

 
#define BOOST_LIB_DIAGNOSTIC 


and watching the linked libraries. It turns out that the chrono library depends on the system library!

BTW I looked up tools for finding component/libraries interdependencies in boost and came across a very interesting tool written by YT Kanalseite called Boost Dependency Analyzer in July 22, 2013.

I found an old (2013) version (at https://meetingcpp.com/index.php/br/items/releasing-boost-dependency-analyzer-1-1.html) and was able to download it.

Could not get it to work with Boost 1.64.0... probably related to the fact that the building with Visual Studio 2017 is broken (I had to download the prebuilt binaries) and the binaries I downloaded were 64 bit - whereas the bcp.exe was 32 bit (which is the only version that will compiler with VS 2017)...

Many thanks as always and specially for making me do some extra work!

Regards,
Juan Dent
Last edited on
Topic archived. No new replies allowed.