[英]Simple Boost Filesystem Access Violation
我試圖使用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位庫:
這些文件位於可執行文件的目錄中:
從此網站下載: 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位庫)。 任何幫助表示贊賞!
這不是解決您發布的問題的答案,但至少可以(通過確認我構建了您發布的示例並且可以與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文件的警告只是表明這些lib / 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 ==========
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.