Remove PDB references from released file
I use to take always a look at the final binary executable or DLL after debugging and creating a file with any IDE. Now I am trying Visual C++ 2010, in the search for the best release, without trash or unnecessary references. So, I created a new solution with two projects: an executable and its DLL. VC++ created a lot of intermediary files between the code and the final file. I opened the .exe and the .dll with a hexadecimal editor and saw something that I don't like. Somewhere inside the file there's an absolute path to the .PDB file.
Why? How can I remove it from VC++?
There must be some pre-processor command for this. What is the use of an absolute path to a .PDB file, like "D:\My Projects\Project1\Release\Project1.pdb" inside the binary of a file that will be distributed on computers with different folders? Besides that, I don't like to see one of my drive's paths saved inside a binary file that I want to share with other people. I am in Release mode, I don't see the use of that unnecessary information. How could I remove it?
You can use /pdbpath:none
(or /pdbaltpath:%_PDB%
on newer versions of link.exe
) to remove the full qualified path name of the PDB file, but keep the name and extension of the PDB only. Keeping the name (and extension) of the PDB for released images is your only way to debug an image that is buggy. Windows images almost always keep the name and extension of the PDBs!
Read the PDB Files documentation on MSDN:
A program database (PDB) file holds debugging and project state information that allows incremental linking of a Debug configuration of your program. A PDB file is created when you compile a C/C++ program with /ZI or /Zi or a Visual Basic/C#/JScript .NET program with /debug.
In Visual C++, the /Fd option names the PDB file created by the compiler. When you create a project in Visual Studio using wizards, the /Fd option is set to create a PDB named project.PDB.
Note that the absolute path is mentioned in the documentation:
The Visual Studio debugger uses the project.PDB file created by the linker directly and embeds the absolute path to the PDB in the EXE or DLL file.
You can always go to Project Properties > Linker > Debugging > Generate Debug Info and set it to No.
If you you cannot rebuild your module (i.e. using the linker switch /PDBPATH:NONE which Microsoft seems to have removed support for), I wrote the peupdate tool for this purpose, as long as you don't mind using a 3rd-party tool. Peupdate can be used to list, remove or change the PDB string in an executable module. Below are some examples:
peupdate -c <module_path> //clear entire PDB path
peupdate -k <module_path> //remove PDB path, but retain filename
peupdate -u <newpath> <module_path> //set your own path string