2009-04-14 96 views
5

我正在使用Visual C++ 2008 SP1。我在調試構建配置中有一個QT應用程序(GUI,.exe)。它被設置爲使用CRT的多線程調試DLL版本,又名MSVCRTD.lib。如何針對發佈版本庫(MSVCRT.lib)構建調試.exe(MSVCRTD.lib)?

我正在建立在發佈模式下並使用多線程DLL(非調試)版本的CRT,又名MSVCRT.lib的第三方庫進行鏈接。

它鏈接並運行,但在啓動時崩潰。鏈接時,我得到警告:

鏈接:警告LNK4098:defaultlib'MSVCRT'與其他庫的使用發生衝突;使用/ NODEFAULTLIB:庫

我試着設置/NODEFAULTLIB:msvcrt.lib

但導致5連接由於缺少符號錯誤。

那麼是不可能使用兩個不同的庫?什麼是替代方案?我可以從我擁有的第三方庫中創建一個DLL嗎?或者是第三方必須做的事情?

在啓動時唯一的例外是:

「在未處理的異常.......在MyApp.exe的:...... 訪問衝突讀取位置0x00000000f」

以下是該應用程序後,調用堆棧上運行,它崩潰了:

MyApp.exe!std::_Aux_cont::_Getcont() + 0xa bytes C++ 
MyApp.exe!std::_Iterator_base_aux::_Getmycont() + 0x1b bytes C++ 
MyApp.exe!std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,unsigned int,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,unsigned int> >,0> >::const_iterator::operator*() + 0x28 bytes C++ 
MyApp.exe!std::_Tree<std::_Tmap_traits<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,unsigned int,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,unsigned int> >,0> >::iterator::operator*() + 0xf bytes C++ 
MyApp.exe!std::map<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,unsigned int,std::less<std::basic_string<char,std::char_traits<char>,std::allocator<char> > >,std::allocator<std::pair<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const ,unsigned int> > >::operator[]() + 0xe9 bytes C++ 
MyApp.exe!ThirdPartyLib::client::`anonymous namespace'::init_xlt_mode() + 0x5f bytes C++ 
[email protected]() + 0x8d8f3 bytes C++ 
msvcr90d.dll!_initterm(void (void)* * pfbegin=0x006c4468, void (void)* * pfend=0x006cb0b8) Line 903 C 
MyApp.exe!__tmainCRTStartup() Line 501 + 0xf bytes C 
MyApp.exe!WinMainCRTStartup() Line 403 C 
kernel32.dll!7c817067()  
+0

你在啓動時遇到什麼樣的崩潰? – LeopardSkinPillBoxHat 2009-04-14 04:12:40

+0

嗨,我剛剛更新了上面的原始帖子,提供了更多的細節和問題的答案。 – ApplePieIsGood 2009-04-14 04:24:49

回答

10

您可以構建您的項目以鏈接到發佈CRT併爲您的代碼啓用調試信息。在「項目屬性」中,轉到C++/General並更改調試信息格式。在「優化」部分關閉優化。切換到「鏈接器/調試」部分並啓用調試信息的生成。確保設置程序數據庫文件(PDB)。

此時,您的應用程序將發出代碼中的所有內容的調試信息,並鏈接到非調試DLL CRT。這使您可以在發佈配置中調試應用程序,同時避免與在同一應用程序中使用多個CRT相關的問題。

2

混合和匹配調試時和Release配置庫我已經看到了這種類似的問題。

雖然這有時可以起作用,但它也可能導致模糊的崩潰,例如您看到的崩潰(可能是由於入口點不匹配或類似原因造成的)。

的替代品,因爲我看到他們是:

  • 建立在Release配置您的應用程序(它指向了MSVCRT.dll),看看這是否正常工作(你將不能夠得到儘可能多的調試信息,但它可能有助於隔離問題的根源)。

  • 如果第三方庫是開源的,請嘗試自己構建.lib文件的Debug版本。

  • 否則,請查看Debug版本是否在線可用,或聯繫供應商。

對不起,我沒有更多的幫助。我認爲從長遠來看,如果能夠訪問正確的庫,然後試圖找出解決方法,它會更快。

+0

我應該說,當我在釋放模式下構建應用程序時,它工作正常,但正如您所說,我無法調試它,因爲我可以告訴它,這使得事情毫無意義。我問供應商,他們起初似乎認爲他們不能提供調試版本。我試圖說服他們。 – ApplePieIsGood 2009-04-14 04:58:00