Search code examples
c++boostwindows-subsystem-for-linuxboost-log

Boost log working on W10 but not in ubuntu - segmentation fault


After testing the Boost.log on W10 with Visual Studio 2019, I am trying to have the same application (writes a simple log file) running in ubuntu using the Windows Subsystem for Linux.

So, I created a new project with the same source files, configured it to build on WSL using GCC, and indicated to the Linker the boost libraries to look for on WSL.

At first, I was getting a lot of linking errors such as "undefined reference to boost::log::v2s_mt_posix..." which disappeared after adding #define BOOST_LOG_DYN_LINK 1 as suggested here: linker error while linking boost log tutorial (undefined references)

With this I was able to start debugging with VS but eventually I get a "segmentation fault" when calling logging::add_common_attributes() in this function

void LOG_InitLogging()
{
    logging::register_simple_formatter_factory<logging::trivial::severity_level, char>( "Severity" );

    logging::add_file_log(
        keywords::file_name = "s.log", //output file
        keywords::format = "[%TimeStamp%] [%LineID%] [%ThreadID%] [%ProcessID%] [%Severity%] ",
        keywords::auto_flush = true
    );

    logging::add_common_attributes();
}

I am not very familiar with linux or linking against libraries so some guidance would be greatly appreciated.

Thank you!


Solution

  • In the VS project, despite correctly indicating the linker (Configuration Properties => Linker => Input => Additional dependencies) to look for boost libraries on WSL, I was also including (Configuration Properties => C/C++ => General => Additional Include directories) the path to the boost headers that are on my Windows system, so IntelliSense would not show those red underlines (I've read somewhere I could do it for that purpose).

    After removing the path to the Windows boost headers, the segmentation fault did not happen ever again.