以前用visual studio 2008時也碰到過類似問題,問題產生的原因就是由于一個Solution下單多個Project是分開編譯的,主項目和子項目的pdb文件名相同(默認都是
vc90.pdb或vc100.pdb)從而造成沖突。這個問題對程序的執行不會產生影響,但會導致丟失部分調試信息。
在網上搜到
解決辦法,修改pdb文件設置的路徑和名稱。轉貼于此。
Project Configuration Properties -> C/C++ -> Output Files
Program Database File
This name, e.g. $(IntDir)\vc90.pdb, is embedded into the object file and it should be the same as the one in
Project Configuration Properties -> Linker -> Debugging
Generate Program Database File
This is, e.g. $(TargetDir)$(TargetName).pdb
Now the object file contain the path where the library is located, too.
由此引出一個話題,那就是對于分開編譯的多個Project組成的一個復雜的Solution如何組織目錄文檔結構,既保持各個Project相對獨立,同時又保證整個Solution調試信息的完整性。我的解決辦法是:首先肯定要像上面一樣修改各單獨Project的pdb的路徑和文件名。其次在復制Project編譯結果到Solution的Lib時,要把所有的obj文件和pdb文件一起copy過來。要注意單獨的Project編譯的obj文件和pdb文件路徑最好相同,而且使用相對路徑"..\"和“.\"打頭。文件復制工作可以寫成一個批處理,放入主Solution的Pre-Build Event中去。