且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用cmake编译静态库的发行版时如何获取pdb文件?

更新时间:2023-11-09 11:43:04

CMake可以像Visual Studio一样为您的VS解决方案生成 RelWithDebInfo 配置.

CMake does - as Visual Studio would do - generate a RelWithDebInfo configuration for your VS solution.

但是您也可以将调试信息添加到其他配置-如 Release -也可以使用例如 target_compile_options() 发电机专家,以提供必要的/Zi /Z7 命令:

But you can add debug info to other configurations - like Release - also with the use of e.g. target_compile_options() and generator experssions to give the necessary /Zi or /Z7 command:

target_compile_options(
    ${PROJECT_NAME} 
    PRIVATE 
         "$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<CONFIG:RELEASE>>:/Zi>"
)

或者您可以使用

or you could just say you want it for all configurations and all targets with add_compile_options() (and without generator expressions for better readability):

project(...)
if (MSVC)
    add_compile_options("/Zi")
endif()

参考