简单的Boost文件系统访问冲突

时间:2012-11-24 17:05:41

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

我正在尝试使用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位库)。任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:0)

这不是解决您发布的问题的答案,但至少会帮助(我希望)通过确认我构建您发布的示例并且它适用于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"

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

关于PDB文件的警告只是说这些libs / 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文件的开头,查看输出窗口,看看究竟是哪些lib链接E.G。:

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 ==========