2012年8月21日 星期二

Visual Studio (as C/C++) 20xx 問題與解決 1

在我使用 VC6 至今(*) VS2010 已經數十年頭, 有些問題常常遇到但很多不知所以然....

(*) sorry, 其實 m$ 在 vs200x 的時候我都還堅守 VC6 啦, 最近才開始混用 VC6 and VS2010


問題1:編譯時遇到下面訊息

xx.lib(oo.obj) : warning LNK4204: 'C:\..\Debug\vc100.pdb' is missing debugging information for referencing module; linking object as if no debug info

原因:
Reason:

1)
這警告是因為要去建立除錯版本時, 使用到外部的某一個程式庫卻沒有該庫對應的 xx.pdb (program database) 檔案, 這檔案包含了一些除錯需要的型別及符號的資訊.

像是你編譯除錯版 (Debug) 的應用程式, 但你引用程式庫全都是發行 (Release) 版, 這樣你無法取得這些庫的偵錯資訊.

It was warning about debugging with particular external lib but without its xx.pdb ( program database) file which contains the type and symbolic debugging information.

It would appear that you're compiling your application in a Debug configuration, but the libraries you referenced are all Release builds, meaning there is no debug information for them.

2)
另外一個可能性是... 該程式庫跟另外一個程式庫用的 .pdb 名字相同 (大多發生在採用預設的 vcx0.pdb), 但在拷貝中檔案被覆蓋過去了.

or in the same name (default as vcx0.pdb) with another .pdb file and been overwrote while copying into.

3)
這也發生在一個 'rebuild solution' 之後, 如果有兩個以上 .vcproj 檔案, 他共享相同的暫時輸出 (intermediate-output) 目錄, 而發生存取相同名字的 'Program Database File Name' (vcx0.pdb) 衝突.

It is also seen after a 'rebuild solution', if two .vcproj files share the same intermediate-output directory and there is a conflict in accessing the same 'Program Database File Name' (vcx0.pdb).


解決 1 和 2:
Solution for 1 and 2:

1)
就忽略這些警告吧 (大家都這樣吧...)

just ignored these warnings (you should already now...)

2)
建立一個程式庫, 把偵錯訊息嵌入進去 (也就是不用 .pdb)

在 Visual Studio 2005/2008/2010 你可以在設定裡這樣做:

Project Properties -> C++ -> General -> Debug Information Format 改成 “/Z7″

一般這選項是預設為 “/ZI” 這樣把偵錯訊息產生在另外的檔案.

make the library to embed the debug information (aka without .pdb)

In Visual Studio 2005/2008/2010 one can do that by setting:

Project Properties -> C++ -> General -> Debug Information Format to “/Z7″

usually this option was set to “/ZI” which generates debug info to external file.

3)
否則找到該 'pdb' (含偵錯訊息) 檔案, 必須放置在跟程式庫相同的目錄下.

otherwise find the 'PDB' file (with debug info) must be placed in the same folder as the libaray.

more info: http://msdn.microsoft.com/en-us/library/958x11bc%28v=VS.100%29.aspx

4)
在 Visual Studio 2005 之前...

避免這個警告,試著按下面步驟建立自己的除錯模式的程式庫:

a) 把 "Debug Information Format" 從 /ZI 改成 Disabled <-- 注意:只有在 vs2005 更早的版本才有
b) 把 "Enable Minimal Rebuild" 從 /Gm 改成 Disabled
c) 改 "Basic Runtime Checks" 為 Default

這基本跟預設的發行磨是設定差不多,少了最佳化. 使用這些設定,你可以移除全部的 OBJ, PDB, 和 IDB 檔案並且使用這些程式庫不會有連結的警告.

before Visual Studio 2005...

To prevent these warnings, try the following to debug mode for my lib:

a) Switched the "Debug Information Format" from /ZI to Disabled <-- note: only available before vs2005
b) Switched the "Enable Minimal Rebuild" from /Gm to Disabled
c) Changed "Basic Runtime Checks" to Default

This is basically the same setup as the default release mode settings, minus the optimization. Using these settings, you can remove all of the OBJ, PDB, and IDB files from compilation and just use the LIB file with no linker warnings.


解決 3:
Solution for 3:

1)
為每一個 .vcproj 修改 Intermediate Output 目錄名字
(在 'Configuration Properties > General > Intermediate Directory' 之下)

change the Intermediate Output dir for one .vcproj
(under 'Configuration Properties > General > Intermediate Directory')

2)
修改 'Program Database File Name' 為另外一個非 VC70.pdb 的名字
(在 'Configuration Properties > C/C++ > Output Files > Program Database File Name' 之下)

change the name of the 'Program Database File Name' to something different than vc70.pdb.
(under 'Configuration Properties > C/C++ > Output Files > Program Database File Name')

沒有留言:

張貼留言