简体   繁体   English

在 clion 中使用 MSVC 工具链时无法调试“iostream”相关代码

[英]Cant debug `iostream` related code when using MSVC toolchain in clion

I am new to c++ development, and I find that I can't place breakpoints in iostream related class and if I force step into call of iostream functions like basic_streambuf::xsgetn I will get a disassembly view which I have absolutely no interest to read.我是 c++ 开发的新手,我发现我无法在与 iostream 相关的 class 中放置断点,如果我强制步入调用basic_streambuf::xsgetn之类的 iostream 函数,我将得到一个我完全没有兴趣阅读的反汇编视图.

I am using clion with Visual Studio Toolchain.我正在使用带有Visual Studio工具链的 clion。 Is there a way to debug normally with those classes?有没有办法用这些类进行正常调试?

By the way, how to use lldb to get actual value of unique_ptr , now I am using ptr._Mypair._Myval2 which seems really ugly....顺便说一下,如何使用lldb来获取unique_ptr的实际值,现在我用的是ptr._Mypair._Myval2 ,看起来真的很难看....

After a few days of digging.经过几天的挖掘。 It turns out that adding the following to CMakeLists.txt fixed the problem事实证明,将以下内容添加到 CMakeLists.txt 解决了问题

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
    message(STATUS " MSVC DEBUG RUNTIME")
    # enable debugging of runtime library
    set_property(TARGET archive_patcher_cpp PROPERTY
            MSVC_RUNTIME_LIBRARY "MultiThreadedDebug")
endif()

Note: this will link runtime statically so the executable size will be a lot bigger , and this requires cmake 3.15 or higher.注意:这将静态链接运行时,因此可执行文件大小会更大,这需要 cmake 3.15 或更高版本。

reference: https://cmake.org/cmake/help/v3.15/prop_tgt/MSVC_RUNTIME_LIBRARY.html参考: https://cmake.org/cmake/help/v3.15/prop_tgt/MSVC_RUNTIME_LIBRARY.html

For cmake lower than 3.15:对于低于 3.15 的 cmake:

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 CLion 和 MSVC 编译器工具链编译 wxWidgets Hello World 应用程序而不会出错? - How do I compile a wxWidgets Hello World app with CLion and the MSVC compiler toolchain without errors? 使用自定义工具链时包括用于CLion检查的目录 - Including directories for CLion inspections while using custom toolchain CLion 支持的工具链版本 - CLion supported toolchain versions 带有扩展iostream的MSVC ++错误 - Error on MSVC++ with extending iostream 如何使用Clion调试外部可执行文件 - How to debug outer executable using Clion 使用gdbserver从Clion调试jni库 - Debug jni library from clion using gdbserver 包含 iostream 时的 VS Code 错误消息 - VS Code error messages when including iostream 为什么使用 __LINE__ 的这段代码在 MSVC 下可以在 Release 模式下编译,但不能在 Debug 模式下编译? - Why does this code using __LINE__ compile under MSVC in Release mode, but not in Debug mode? 我可以在 CLion/Xcode 中调试我的 Kotlin 代码吗? - Can I debug my Kotlin code in CLion/Xcode? 使用CLion / CMake / MSVC 2015编译WIN32应用程序时出现链接错误 - Link error when compiling WIN32 application with CLion/CMake/MSVC 2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM