MantisBT - CMake
View Issue Details
0010636CMakeCMakepublic2010-04-28 15:572016-06-10 14:31
Eric Gross 
Kitware Robot 
normalminoralways
closedmoved 
CMake-2-8 
 
0010636: Visual Studio 'Release' configuration should have usable PDBs generated
I noticed that the 'Release' configuration has the compilation step not produce debug info (/Zi flag). The linker is still configured to produce a PDB but this contains pretty much no information since the compiled code had no debug info generated. This is a problem because any binaries that we produce and ship to customers always needs preserved symbol information for debugging crash dumps from the field or just doing live debugging with the released binaries.

I tried to use the 'ReleaseWithDebugInfo' configuration, but this is a far different configuration than the 'Release' configuration. It is built with incremental linking, inlining options, and unused symbol removal options. It might be useful for some people to debug issues that only appear in optimized code, but the differing compile/link options make these binaries unsuitable for actual release because they are around 50% larger than 'Release' configuration.

Since MSVC has the ability to generate external PDBs for fully-optimized code with no runtime size or performance penalty to the resulting binaries, it seems silly that there is no configuration that lets you do this. I think the default 'Release' configuration should always produce a usable PDB.
The workaround I put in our configuration is the following:

###############################################################################
# Ensure all builds always have debug info built
###############################################################################
IF(WIN32)
    add_definitions("/Zi")
    #--------------------------------------------------------------------------
    # Since /Zi implies /OPT:NOREF, explicitly enable /OPT:REF on all
    # release builds (this ensures all unused symbols are stripped)
    #--------------------------------------------------------------------------
    set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /OPT:REF")
    set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL} /OPT:REF")
    set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF")
ENDIF()
No tags attached.
Issue History
2010-04-28 15:57Eric GrossNew Issue
2011-01-17 15:56David ColeAssigned To => David Cole
2011-01-17 15:56David ColeStatusnew => assigned
2011-01-17 16:04Eric GrossNote Added: 0024813
2011-10-25 22:21David ColeAssigned ToDavid Cole =>
2011-10-25 22:21David ColeStatusassigned => backlog
2013-11-27 11:39Christian BühlerNote Added: 0034592
2013-11-27 11:43Christian BühlerNote Edited: 0034592bug_revision_view_page.php?bugnote_id=34592#r1322
2016-06-10 14:27Kitware RobotNote Added: 0041688
2016-06-10 14:27Kitware RobotStatusbacklog => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:27Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0024813)
Eric Gross   
2011-01-17 16:04   
As an update, the workaround I listed previously was not quite correct as it generated warnings in some configurations. Someone else fixed this in our trunk to only add the /Zi flag during release builds rather than always. This is the workaround we use currently:

###############################################################################
# Ensure all builds always have debug info built
###############################################################################
IF(WIN32)
    # make the Release version create a PDB
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
    # minimize the size or the resulting DLLs
    set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /OPT:REF")
ENDIF()
(0034592)
Christian Bühler   
2013-11-27 11:39   
(edited on: 2013-11-27 11:43)
I am using CMAKE_EXE_LINKER_FLAGS_RELEASE instead of CMAKE_SHARED_LINKER_FLAGS_RELEASE and added /DEBUG additonally

(0041688)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.