【问题标题】:Simple Boost Filesystem Access Violation简单的 Boost 文件系统访问冲突
【发布时间】:2012-11-24 17:05:41
【问题描述】:

我正在尝试使用 boost::filesystem 列出当前目录中的项目,但我得到:

Unhandled exception at 0x6B59DF8D (msvcr110.dll) in BoostTest.exe: 0xC0000005: Access violation reading location 0x9BE3B7A1.

这是我的代码:

#include <iostream>
#include <boost/filesystem.hpp>

using namespace boost::filesystem;

int main() {
    std::cout << "Hello World!\n";
    auto end_it = directory_iterator();
    for(auto it = directory_iterator(current_path()); it != end_it; it++) {
        std::cout << it->path() << std::endl;
    }
    std::cin.get();
    return 0;
}

我刚刚从 mingw 切换到 vs2012,我认为这可能是一个链接错误或类似的东西。我正在链接这些 32 位库:

  • boost_filesystem-vc110-mt-1_52.lib

而且这些文件都在可执行文件的目录下:

  • boost_filesystem-vc110-mt-1_52.dll
  • boost_system-vc110-mt-1_52.dll

从本网站下载:http://boost.teeks99.com/

并且平台设置为“Win32”。

这是来自 Visual Studio 2012 窗口的日志:

'BoostTest.exe' (Win32): Loaded 'C:\Users\Ell\Programming\C++\BoostTest\Debug\BoostTest.exe'. Symbols loaded.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Users\Ell\Programming\C++\BoostTest\Debug\boost_filesystem-vc110-mt-1_52.dll'. Module was built without symbols.
'BoostTest.exe' (Win32): Loaded 'C:\Users\Ell\Programming\C++\BoostTest\Debug\boost_system-vc110-mt-1_52.dll'. Module was built without symbols.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110.dll'. Symbols loaded.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110.dll'. Symbols loaded.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp110d.dll'. Symbols loaded.
'BoostTest.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcr110d.dll'. Symbols loaded.
First-chance exception at 0x6B59DF8D (msvcr110.dll) in BoostTest.exe: 0xC0000005: Access violation reading location 0x9BF7B7A1.
Unhandled exception at 0x6B59DF8D (msvcr110.dll) in BoostTest.exe: 0xC0000005: Access violation reading location 0x9BF7B7A1.
The program '[5292] BoostTest.exe' has exited with code 0 (0x0).

我的平台是带有visual studio 2012 64位编译器的windows 7 64位。

我只在 linux 和 mingw 上开发过,所以很可能是我链接错误或类似的东西 - 可能是架构问题(尽管我的印象是 32 位应用程序使用 32 位库)。任何帮助表示赞赏!

【问题讨论】:

    标签: c++ windows visual-studio architecture linker


    【解决方案1】:

    这不是解决您发布的问题的答案,但至少会帮助(我希望)确认我构建了您发布的示例并且它适用于 32 位库:

    Hello World! 
    
    "C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\TestOperator\Debug" 
    "C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\TestOperator\ReadMe.txt"
    "C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\TestOperator\stdafx.cpp" 
    "C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\TestOperator\stdafx.h" 
    "C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\TestOperator\targetver.h"
     "C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\TestOperator\TestOperator.cpp" 
    "C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\TestOperator\TestOperator.vcxproj"
     "C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\TestOperator\TestOperator.vcxproj.filters"
    

    我从您上面引用的站点下载了库 (32/64),并且根据 This,我遇到了 64 位版本的链接错误。 (我有 64 位操作系统、编译器等。)当我与 32 位版本链接时,它一切正常,如上所述。

    您收到的有关 PDB 文件的警告只是说调试信息在这些库/dll 中不可用的消息 - 所以基本上没有,原则上,我认为您没有做错任何事情。

    如果 Boost 抛出异常,那么您可以使用以下方法获得更多信息:

    #include <boost/exception/diagnostic_information.hpp>
    
    ...
    
    catch(...)
    {
        std::cerr << "Unhandled exception!" << std::endl <<
        boost::current_exception_diagnostic_information();
        return 0;
    }
    

    最后一件可能有帮助的事情是添加

    #define BOOST_LIB_DIAGNOSTIC
    

    到主 cpp 文件的开头并查看输出窗口以查看正在链接的库。例如:

    1>  stdafx.cpp
    1>  TestOperator.cpp
    1>  Linking to lib file: libboost_system-vc110-mt-gd-1_52.lib
    1>  Linking to lib file: libboost_filesystem-vc110-mt-gd-1_52.lib
    1>  TestOperator.vcxproj -> C:\Users\john\Documents\Visual Studio 2012\Projects\TestOperator\Debug\TestOperator.exe
    ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-06
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多