Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake - extracting pdb files from object libraries

I am building my static library using the object libraries as shown using CMake 3.1.3.

I have

ADD_SUBDIRECTORY(A)
ADD_SUBDIRECTORY(B)
....
ADD_LIBRARY(mylib STATIC ${SOURCES}
                  $<TARGET_OBJECTS:A> 
                  $<TARGET_OBJECTS:B> )
SET_TARGET_PROPERTIES(mylib PROPERTIES COMPILE_PDB_NAME mylib COMPILE_PDB_OUTPUT_DIR ${CMAKE_BINARY_DIR})

Now, my problem is A generates vc120.pdb in A's CMake subdirectory. B generates its own vc120.pdb in B's CMake subdirectory. And, mylib generates mylib.pdb in the main binary cmake folder.

I only want one static library and one pdb file. I just want mylib and mylib.pdb.

How can I merge all the vc120.pdbs into mylib.pdb or ideally just generate only one pdb file?

like image 804
Nick Avatar asked Apr 09 '15 18:04

Nick


2 Answers

This is not a direct answer to your question, but an alternate solution you may want to consider.

With static libraries, you are probably better off using /Z7 for the generation of debugging information. When using /Z7 the compiler does not produce a .PDB file, but embeds debugging info directly into the generated object files.

When these object files are then linked as a static library, lib.exe will copy the debugging info from all object files to the resulting .lib file. There is not need to distribute a .pdb file with the .lib file.

Unlike link.exe, which is used by CMake to produce a DLL or and EXE, lib.exe does not have an option to output a .PDB file.

Via CMake you can set the required options in the following way. For the object library use:

add_library(A OBJECT lib2.cpp)
set_target_properties(A PROPERTIES COMPILE_OPTIONS "/Z7")

To produce the final static library, use:

add_library(mylib STATIC main.cpp $<TARGET_OBJECTS:A> $<TARGET_OBJECTS:B> )
set_target_properties(mylib PROPERTIES COMPILE_OPTIONS "/Z7")
like image 124
sakra Avatar answered Oct 20 '22 17:10

sakra


I have managed to contact folks at Kitware (CMake owner).

They have said,

"Set the COMPILE_PDB_* properties of A, B, and mylib all to point to the same place. Object libraries are built independently and do not know what will consume them (or if multiple targets consume them), so they need to be configured individually."

So, inside A & B, do

add_library(A OBJECT a.c)
set_target_properties(A PROPERTIES
    COMPILE_PDB_NAME "mylib"
    COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
like image 42
Nick Avatar answered Oct 20 '22 17:10

Nick