解決 DLL Hell 的方法是 … 造一個新的 Hell …

March 7th, 2007

最近開始使用 Visual Studio 2005 SP1 (a.k.a. VS8 SP1) 來開發程式,VS8 與之前版本最大的不同在於 CRT library 會安裝到 WinSxS,這是為了解決 DLL hell 的問題,至少 VC team 的 development lead Martyn Lovell’s 的 blog 是這麼寫的。

因此,VC linker 會自動產生 manifest 檔案並將它包入你的 DLL 或 EXE,不幸的是,這玩意兒造出了一個新的 hell。以下是一個例子:

我有一個 setup.exe 用到了兩個 delayed-load DLL,一個叫 comp8.dll,另一個叫 comp8sp1.dll。comp8.dll 是買來的元件,用 VC8 (CRT version 8.0.50608.0) 編譯成的,另一個元件 comp8sp1.dll 則是我自己的 DLL,用 VC8 SP1 (CRT version 8.0.50727.363) 製成。VC8 linker 為 setup.exe 自動產生的 manifest 像這個樣子

<dependency>
<dependentAssembly>
<assemblyIdentity type=’win32′ name=’Microsoft.VC80.CRT’ version=’8.0.50727.762′ processorArchitecture=’x86′ publicKeyToken=’1fc8b3b9a1e18e3b’ />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity type=’win32′ name=’Microsoft.VC80.CRT’ version=’8.0.50608.0′ processorArchitecture=’x86′ publicKeyToken=’1fc8b3b9a1e18e3b’ />
</dependentAssembly>
</dependency>

這個錯誤的 manifest 就是惡名昭彰的 “incorrect application configuration” 問題 (不太清楚中文 Windows 上怎麼翻的)。如果你在一般的 XP SP2 機器上執行這個 setup.exe 的話,多半會直接掛掉,因為大部份的機器都沒有安裝 VC8 SP1 的 runtime redist。問題是這個 setup.exe 本來就是設計用來安裝這些 runtime 的啊!

如果你也遇到相同的 manifest hell,這個連結有正確的除錯方法。若想深入了解 side-by-side 這玩意,CodeProject 的這篇好文章有詳細的解釋。

C++/C#, Windows, 狀況排解 | Comments Jump to the top of this page

Comments are closed.

隨便寫寫大家隨便看看的不出名小格子

舊文索引

站內管理