In my app I include boost/system/error_code.hpp
(boost 1.58) but don't want to link to boost_system, but instead have a header-only solution. I read by defining BOOST_ERROR_CODE_HEADER_ONLY
that should be possible. But unfortunately, it does not work as expected. I still get a linker error for boost::system::system_category().
I wonder if that is supposed to work at all and if so how. The code in the boost header is:
# ifdef BOOST_ERROR_CODE_HEADER_ONLY
inline const error_category & system_category() BOOST_SYSTEM_NOEXCEPT;
inline const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT;
#else
BOOST_SYSTEM_DECL const error_category & system_category() BOOST_SYSTEM_NOEXCEPT;
BOOST_SYSTEM_DECL const error_category & generic_category() BOOST_SYSTEM_NOEXCEPT;
#endif
and as you can see there is no body defined for system_category(). How can this work at all without linking to a lib?
Update:
In the meantime I found where the body of that declaration is defined (in boost/system/detail/error_code.hpp
which is included by the boost/system/error_code.hpp
file. Still it does not avoid the linker errors. I'm working in XCode (llvm C++11) and have defined BOOST_ERROR_CODE_HEADER_ONLY
in the target settings, if that matters.