使用cmake编译静态库的发行版时如何获取pdb文件? [英] How to get pdb files while compiling release version of static library using cmake?

查看:203
本文介绍了使用cmake编译静态库的发行版时如何获取pdb文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个静态库,正在使用cmake进行编译.现在,当我精通调试模式时,会生成pdb文件,但是在编译发布模式时,不会生成pdb文件.以下是cmake中的一段代码:

I have a static library which i am compiling using cmake. Now, when i comiple in debug mode i get pdb file generated but when release mode is compiled the pdb file is not generated. Following is the piece of code in cmake:

    if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
        set_target_properties(${PROJECT_NAME} PROPERTIES IMPORTED_CONFIGURATIONS "Debug")
        set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_PDB_NAME ${PROJECT_NAME} COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bin_debug" )
    elseif("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
        set_target_properties(${PROJECT_NAME} PROPERTIES IMPORTED_CONFIGURATIONS "Release")
        set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_PDB_NAME ${PROJECT_NAME} COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bin_release" )

我想拥有用于调试以及发布版本的pdb文件.所以,我怎么能拥有它?确实需要建议.

I want to have pdb files for debug as well as release build. So,how can i have it? Suggestions are really required.

推荐答案

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

参考

这篇关于使用cmake编译静态库的发行版时如何获取pdb文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆