由于访问冲突,Boost::Program_Options 未处理异常

发布于 2024-11-17 14:47:18 字数 2118 浏览 4 评论 0原文

我有一个程序在调试模式下运行良好,但在发布模式下由于访问冲突而出现未处理的异常。我很确定这不是由于空指针造成的。这是调用堆栈:

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.

I have a program that runs fine in DEBUG mode but in RELEASE mode I get an unhandled exception due to an access violation. I'm pretty sure it's not due to null pointers. Here is the call stack:

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

Code:

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
*/
}

The exception reads:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-11-24 14:47:18

有些东西很时髦。为什么 argc 是 4233952?您能验证这不仅仅是调试器的产物吗?

我建议您重建项目,如果这不能解决问题,请在加载所有内容后调试程序并查看“模块”窗口。您可能混合了不兼容的库,例如 DLL/EXE 的发布版本和调试版本。

请特别注意已加载的 CRT 文件、msvcr90d 等。查看已加载的所有 CRT DLL 的文件版本信息并验证它们是否都具有相同的版本。

Something's funky. Why is argc 4233952? Can you verify that that is not just an artifact of the debugger?

I suggest you rebuild your project, and if that doesn't fix it, then debug the program after everything is loaded and look at the "modules" window. You may be mixing incompatible libraries, e.g. release and debug versions of DLL's/EXE's.

Pay special attention to the CRT files that were loaded, msvcr90d, etc. Look at the file version info of all the CRT DLL's that were loaded and verify that they all have the same version.

永不分离 2024-11-24 14:47:18

我认为我可能面临的问题是我的程序从 DEBUG CRT DLL 加载符号。当发生访问冲突时,RELEASE CRT DLL 中的符号尚未加载。我已经检查了我的程序中涉及的所有项目,它们都使用多线程 DLL (/MD),但它仍然使用它的调试版本。

I think the problem I may be facing is that my program loads the symbols from the DEBUG CRT DLL's. By the time the access violation occurs, the symbols from the RELEASE CRT DLL's are not loaded. I have checked all the projects involved in my program and they all use a Multi-threaded DLL (/MD) and yet it's still using the debug version of it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文