Subject: [Boost-bugs] [Boost C++ Libraries] #12176: Chrono without linking to Boost.System
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-05-04 13:06:01
#12176: Chrono without linking to Boost.System
------------------------------+---------------------
Reporter: eldiener | Owner:
Type: Bugs | Status: new
Milestone: To Be Determined | Component: None
Version: Boost 1.61.0 | Severity: Problem
Keywords: |
------------------------------+---------------------
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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12176> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC