2011-06-28 99 views
-2

我有一個程序在DEBUG模式下運行正常,但在RELEASE模式下,由於訪問衝突,我得到一個未處理的異常。我很確定這不是由於空指針。這裏是調用堆棧:Boost :: Program_Options由於訪問衝突導致未處理的異常

msvcr90d.dll!memchr(unsigned char * buf=0x0000002c, unsigned char chr='', unsigned long cnt=1243588) Line 80   Asm 
msvcp90d.dll!std::char_traits<char>::find(const char * _First=0x72656d6f, unsigned int _Count=15, const char & _Ch=',') Line 590 + 0x15 bytes  C++ 
msvcp90d.dll!std::basic_string<char,std::char_traits<char>,std::_DebugHeapAllocator<char> >::find(const char * _Ptr=0x0012f9e4, unsigned int _Off=0, unsigned int _Count=1) Line 1796 + 0x2d bytes C++ 
Program.exe!boost::program_options::option_description::set_name() + 0x61 bytes C++ 
Program.exe!boost::program_options::option_description::option_description() + 0x90 bytes C++ 
Program.exe!boost::program_options::options_description_easy_init::operator()() + 0x58 bytes   C++ 
Program.exe!CommandLineInput(int count=2, char * * vector=0x003d3360) Line 191 + 0xac bytes   C++ 
Program.exe!main(int argc=4233952, char * * argv=0x00000002) Line 65535  C++ 
Program.exe!__tmainCRTStartup() Line 582 + 0x17 bytes   C 

代碼:

namespace po = boost::program_options; 

int _tmain(int argc, _TCHAR* argv[]) 
{ 
     try 
     { 
      CommandInput (argc, argv); //get command line input 
     } 
     catch (std::exception e) 
     { 
      std::cout << "WARNING: Exception is thrown" << std::endl; 
      return 0; 
     } 
} 

void CommandInput (int count, _TCHAR* vector[]) 
{ 
     po::options_description desc("Available Parameters"); 
     std::cout << "\n"; 
     desc.add_options() 
      ("option1", po::value<std::string>(), "description1") 
      ("option2", po::value<std::string>(), "description2") 
      ("option3", po::value<std::string>(), "description3"); 

/* 
The code breaks at the above line 
*/ 
} 

異常寫着:

Unhandled exception at 0x1026f09b (msvcr90d.dll) in Program.exe: 0xC0000005: Access violation reading location 0x72656d6f. 
+4

怎麼樣顯示代碼? – Mat

+0

問題是工作相關,所以我不願意發佈任何代碼。但是現在我編輯我的帖子來插入模擬代碼,類似於實際代碼的樣子。 – Dan

回答

0

我認爲我可能面臨的問題是我的程序從DEBUG CRT DLL中加載符號。在發生訪問衝突時,RELEASE CRT DLL的符號不會被加載。我檢查了我的程序中涉及的所有項目,它們都使用多線程DLL(/ MD),但它仍然使用它的調試版本。

+0

我發現了這個問題。看來我正在鏈接到我的項目的屬性頁面中調試Boost庫(「libboost_regex-vc90-mt-gd-1_42.lib」是罪魁禍首)。我通過轉到Properties-> Linker-> Input-> Additional Dependencies來修復它,並將庫名改爲指向Release版本。 – Dan

0

東西的時髦。爲什麼是argc 4233952?你能證實這不僅僅是調試器的人工產物嗎?

我建議你重建你的項目,如果沒有解決它,然後調試程序後加載一切,看看「模塊」窗口。您可能混合了不兼容的庫,例如發佈和調試DLL的/ EXE的版本。

請特別注意加載的CRT文件,msvcr90d等。查看加載的所有CRT DLL的文件版本信息,並確認它們都具有相同的版本。

+0

嗨大衛,我不確定你是什麼意思的「調試器的人工製品」。你能澄清這一點嗎?此外,加載的模塊是系統DLL的,所以我不認爲混合DEBUG和RELEASE DLL的問題。 CRT DLL的版本號相同,但我認爲我發現了一些可疑的東西。我的程序(在RELEASE中運行)加載了DEBUG CRT DLL的符號(在「x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456」文件夾中找到),而不是「x86_Microsoft.VC90」中CRT DLL的符號。 CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_597c3456「文件夾。 – Dan

+0

另外,argv的值爲0x00000002 ...它看起來像兩個可能交換? 2的argc和0x00409AE0的argv會更有意義。 – qid

+0

這是一個有趣的觀察。但是,我不認爲這是問題的原因,因爲訪問衝突錯誤發生在使用任何參數之前(它在desc.add_options()行處中斷)。 – Dan

相關問題