Boost 日志在 W10 上工作但在 ubuntu 中不工作 - 分段错误

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

在使用 Visual Studio 2019 在 W10 上测试 Boost.log 之后,我试图在 ubuntu 中使用相同的应用程序(写入一个简单的日志文件)运行 Linux.

的 Windows 子系统

因此,我使用相同的源文件创建了一个新项目,将其配置为使用 GCC 在 WSL 上构建,并向链接器指示要在 WSL 上查找的升压库。

起初,我遇到了很多链接错误,例如“对 boost::log::v2s_mt_posix 的未定义引用...”,这些错误在添加后消失了 #define BOOST_LOG_DYN_LINK 1 此处建议:linker error while linking boost log tutorial (undefined references)

有了这个我就可以开始使用 VS 进行调试了,但最终我在这个函数中调用 logging::add_common_attributes() 时遇到了“分段错误”

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();
}

我不太熟悉 linux 或链接库,因此非常感谢一些指导。

谢谢!

在 VS 项目中,尽管正确指示了链接器(配置属性 => 链接器 => 输入 => 附加依赖项)以在 WSL 上查找增强库,但我还包括(配置属性 => C/C++ => General => Additional Include directories)我的 Windows 系统上的 boost headers 的路径,因此 IntelliSense 不会显示那些红色下划线(我读过我能做的地方为此目的)。

删除 Windows 提升 headers 的路径后,分段错误就再也没有发生过。