0
votes

I built a 3rd party static library in a folder called <libraryBuildDir> and copied the resulting *.lib file into my projects folder structure. Along with the *.lib, I also placed the *.pdb file. Then I deleted <libraryBuildDir>, assuming it's no longer needed. This is what worked for other libraries before and it follows what seems to be a common practice.

However, when I build my project in debug configuration I get many LNK4099 warnings like this (roughly translated):

<myLib>.lib(<someObjFromTheLib>.obj) : warning LNK4099: PDB "<myLib>.pdb" was not found alongside "<myLib.lib>" or "<myBuildDir>". Linking without debug info

I verified that the *.pdb file is there right next to the *.lib file. As a test, I placed it right into the build directory, as suggested by the warning. Now I get many LNK4204 like this:

<myLib>.lib(<someObjFromTheLib>.obj) : warning LNK4204: "<myBuildDir>\<myLib>.pdb" is missing debugging information for referencing module; linking object as if no debug info

I followed this advice to extract one of the object files that appeard in my warnings, (<someObjFromTheLib>.obj). I noticed that the extracted *.obj file did not contain a Debug$T section.

So apparently when I copied the *.pdb file from <libraryBuildDir> to my project, I broke some links to other debug symbol files that are now not available anymore, because I deleted <libraryBuildDir>. This makes me think that my whole process is wrong.

My goal: Compile the static library with debug symbols and move the finished *lib file to another project. Then compile the other project and include the full debug symbols from the static library.

How can I move a pdb file from a temporary library build directory to another directory without breaking any references?

(Sidenote: I'm compiling Crypto++ v8.2.0 using cmake and the *.pdb file is called cryptopp-object.pdb whereas the library is called cryptopp-static.lib. This goes against the convention that *.lib and *.pdb have the same name, but it is how Crypto++ is configured and I don't want to change that if possible. However, the *.lib file seems to expect the correct name for its pdb file so I assume that this is fine.)

(Also: lib /list <myLib>.lib lists a lot of *.obj files and only some of those appear in my LNK4099 warnings, whereas others don't. I don't know if that means they're simply not used in my project or if they have all debug information available.)

2
The linking is done from the linker includes folders, are the pdbs there? Is the pdb and lib from the same “build“? Are you mixing Release and Debug builds?Robert Andrzejuk
You can use the /Fd compile option to put the program database in a directory that you are not going to delete. But certainly much easier to just not delete that directory.Hans Passant
@Robert Andrzejuk Yes, the pdb files are in the include folders right next to the actual lib file. And no, I did compile the lib first and copied the pdb from another build, assuming that a build is deterministic and produces the same output everytime (no settings were change in between). Turns out, If I recompile and copy the lib and pdb from the exact same run, the problem seems to disappear. Why on earth are the results not deterministic?LoveDaOOP
What do You mean deterministic? The lib and pdb have to be copied together.Robert Andrzejuk

2 Answers

0
votes

Turns out, If I recompile and copy the lib and pdb from the exact same run, the problem seems to disappear.

Why on earth are the results not deterministic?

a) Because the PDB contains a timestamp and that timestamp will rarely be the same on different builds

b) Because builds can be multi-threaded nowadays, thus leading to different results, depending on what is compiled first.

c) The "same" code (with regards to behavior) could produce a different AST, e.g. if you just moved methods around.

How can I move a pdb file from a temporary library build directory to another directory without breaking any references?

It should be possible as long as the PDB matches the build. However, consider building into the desired directory using the /Fd option for the PDB and /Fo option for the OBJ.

-1
votes

Solution: Builds are not deterministic. The *.pdb and *.lib files have to be from the exact same "build".