Opened 6 years ago

Closed 6 years ago

#12176 closed Bugs (fixed)

Chrono without linking to Boost.System

Reported by: Edward Diener Owned by: viboes
Milestone: Boost 1.62.0 Component: chrono
Version: Boost 1.61.0 Severity: Problem
Keywords: Cc:

Description

In the chrono docs we have:

How to Build Boost.Chrono as a Header Only Library?

When BOOST_CHRONO_HEADER_ONLY is defined the lib is header-only.

If in addition BOOST_USE_WINDOWS_H is defined <windows.h> is included, otherwise files in boost/detail/win are used to reduce the impact of including <windows.h>.

However, you will either need to define BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING or link with Boost.System.

But when I followed this chrono still linked with Boost.System. Here is the code:

#define BOOST_CHRONO_HEADER_ONLY
#define BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
// #define BOOST_SYSTEM_NO_DEPRECATED

#include <iostream>
#include <boost/chrono.hpp>
#include <boost/ratio.hpp>

int main()
  {
  typedef boost::chrono::duration<int, boost::ratio<1, 100000000> > shakes;
  typedef boost::chrono::duration<int, boost::centi> jiffies;
  typedef boost::chrono::duration<float, boost::ratio<12096,10000> > microfortnights;
  typedef boost::chrono::duration<float, boost::ratio<3155,1000> > nanocenturies;
  boost::chrono::seconds sec(1);
  std::cout << "1 second is:\n";
  std::cout << boost::chrono::duration_cast<shakes>(sec).count()
              << " shakes\n";
  std::cout << boost::chrono::duration_cast<jiffies>(sec).count()
              << " jiffies\n";
  std::cout << microfortnights(sec).count() << " microfortnights\n";
  std::cout << nanocenturies(sec).count() << " nanocenturies\n";
  return 0;
  }

The link error message is:

gcc.link C:\Programming\VersionControl\modular-boost\build\boost\bin.v2\libs\cxx_dual\test\test_chrono_boost.test\gcc-mingw-5.3\debug\test_chrono_boost.exe
C:\Programming\VersionControl\modular-boost\build\boost\bin.v2\libs\cxx_dual\test\test_chrono_boost.test\gcc-mingw-5.3\debug\test_chrono_boost.o: In function `_static_initialization_and_destruction_0':
E:\Programming\VersionControl\modular-boost\libs\cxx_dual\test/../../../boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
E:\Programming\VersionControl\modular-boost\libs\cxx_dual\test/../../../boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
E:\Programming\VersionControl\modular-boost\libs\cxx_dual\test/../../../boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
collect2.exe: error: ld returned 1 exit status

If I uncomment the line:

// #define BOOST_SYSTEM_NO_DEPRECATED

then chrono links without requiring Boost.System.

Maybe this bug is one of documentation and the documentation should be changed to specify that BOOST_SYSTEM_NO_DEPRECATED must also be defined in order to remove the chrono dependency on Boost.System.

Change History (5)

comment:1 by Edward Diener, 6 years ago

Component: Nonechrono
Owner: set to viboes

comment:2 by viboes, 6 years ago

Status: newassigned

comment:3 by Edward Diener, 6 years ago

The latest change on develop fixes the issue.

comment:4 by viboes, 6 years ago

Milestone: To Be DeterminedBoost 1.62.0

comment:5 by viboes, 6 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.