1

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!

  • There's nothing obviously wrong with the code you posted, so my guess is the problem is elsewhere. Please post a complete short repro, with compiler options and backtrace of the crash. – Andrey Semashev Oct 06 '21 at 11:49
  • 1
    @AndreySemashev After your comment I was trying to reproduce again the problem and it didn't happen. Just like magic. However, there is an explanation. I was including on VS the path to boost headers in my windows systems so IntelliSense would not show those red underlines (read somewhere I could do it for that purpose). Eventually I removed that path and that is the only difference since my post. Just tested to use the path again and got the segmentation fault. – user10279396 Oct 06 '21 at 16:14

1 Answers1

1

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.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 06 '21 at 16:24
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 06 '21 at 19:06
  • 1
    I agree with the Review comments. I think you had a good question, and it's likely that your experience and answer could help others in the future, but it would be great if you could include more details. It sounds like you are saying that you had Windows headers in a Linux/WSL project, but it's not quite clear, especially to someone reading this without the same level of WSL understanding. Thanks! – NotTheDr01ds Oct 06 '21 at 22:47