In my code using Boost.Log I register a formatter for my log output
register_simple_formatter_factory<LogLevel, char>("Severity");
This worked as expected for some time but now I tried to build on a different platform and are getting a linker error
undefined reference to `void boost::log::v2s_mt_posix::register_formatter_factory<char>(boost::log::v2s_mt_posix::attribute_name const&, boost::shared_ptr<boost::log::v2s_mt_posix::formatter_factory<char> > const&)'
My guess is that this is because the installed library from the package repository was build with BOOST_LOG_WITHOUT_DEFAULT_FACTORIES
defined. According to the Boost.Log documentation this means that
the user will have to register all attributes in the library before parsing any filters or formatters from strings.
But how do I do this? What specifically do I have to replace my call to register_simple_formatter_factory
with to have the same effect.
My guess is that this is because the installed library from the package repository was build with
BOOST_LOG_WITHOUT_DEFAULT_FACTORIES
defined.
No, this is not the reason for the linking error. Disabling default factories does not remove factory registration APIs.
But how do I do this? What specifically do I have to replace my call to
register_simple_formatter_factory
with to have the same effect.
You don't need to replace register_simple_formatter_factory
with anything. On the contrary, you must call register_simple_formatter_factory
or register_formatter_factory
for every attribute you use, even if you didn't have to before. Same for filters (register_filter_factory
, register_simple_filter_factory
). Where previously the default factories were used, you must now create and register ones manually.
Regarding linking errors, check this first. Make sure the namespace names in the library you link with match those in the linker error. If not, define configuration macros to rectify the mismatch.
Also, make sure you're linking with boost_log_setup
, not just boost_log
. boost_log_setup
should go before boost_log
in the linker command line.