简体   繁体   English

在 Visual Studio 2019 下为 Debug 模型编译时,哪些配置错误可能导致 Boost Filesystem 因访问冲突而失败?

[英]What misconfiguration might cause Boost Filesystem to fail with an access violation when compiled for Debug model under Visual Studio 2019?

I am struggling to understand why some of my code using boost, which was working fine under Visual Studio 2017, is now resulting in an access violation under Visual Studio 2019. However, I only encounter this failure under Debug build.我正在努力理解为什么我的一些使用 boost 的代码(在 Visual Studio 2017 下运行良好)现在导致在 Visual Studio 2019 下出现访问冲突。但是,我只在调试构建下遇到此故障。 Release build works fine, with no issues.发布构建工作正常,没有问题。

What could I have set up incorrectly in my build, environment, or code, that could cause such a failure?在我的构建、环境或代码中,我有哪些可能会导致此类失败的错误设置?

My environment:我的环境:

  • Windows 10视窗 10
  • Boost 1.74 (dynamic link) Boost 1.74(动态链接)
  • Visual Studio 2019 v16.7.6 Visual Studio 2019 v16.7.6
  • Compiling for C++ x64为 C++ x64 编译

The failing line of my code is this:我的代码的失败行是这样的:

boost::filesystem::path dir = (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path("%%%%-%%%%-%%%%-%%%%"));

The failing line in Boost filesystem is this here in boost/filesystem/path.hpp : Boost 文件系统中的失败行在boost/filesystem/path.hpp

namespace path_traits
{  //  without codecvt

  inline
    void convert(const char* from,
    const char* from_end,    // 0 for null terminated MBCS
    std::wstring & to)
  {
    convert(from, from_end, to, path::codecvt());
  }

The failure message reported by Visual Studio is as follows: Visual Studio 上报的失败信息如下:

Exception thrown at 0x00007FF9164F1399 (vcruntime140d.dll) in ezv8.tests.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

The call stack looks like this:调用堆栈如下所示:

    vcruntime140d.dll!00007ff9164f1550()    Unknown
>   boost_filesystem-vc142-mt-gd-x64-1_74.dll!wmemmove(wchar_t * _S1, const wchar_t * _S2, unsigned __int64 _N) Line 248    C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!std::_WChar_traits<wchar_t>::move(wchar_t * const _First1, const wchar_t * const _First2, const unsigned __int64 _Count) Line 204 C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!std::wstring::append(const wchar_t * const _Ptr, const unsigned __int64 _Count) Line 2864 C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!std::wstring::append<wchar_t *,0>(wchar_t * const _First, wchar_t * const _Last) Line 2916    C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!`anonymous namespace'::convert_aux(const char * from, const char * from_end, wchar_t * to, wchar_t * to_end, std::wstring & target, const std::codecvt<wchar_t,char,_Mbstatet> & cvt) Line 77 C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!boost::filesystem::path_traits::convert(const char * from, const char * from_end, std::wstring & to, const std::codecvt<wchar_t,char,_Mbstatet> & cvt) Line 153   C++
    appsvcs.dll!boost::filesystem::path_traits::convert(const char * from, const char * from_end, std::wstring & to) Line 1006  C++
    appsvcs.dll!boost::filesystem::path_traits::dispatch<std::wstring>(const std::string & c, std::wstring & to) Line 257   C++
    appsvcs.dll!boost::filesystem::path::path<char [20]>(const char[20] & source, void * __formal) Line 168 C++

I use UTF-8 strings throughout my code, so I have configured boost::filesystem to expect UTF-8 strings as follows:我在整个代码中使用 UTF-8 字符串,因此我将 boost::filesystem 配置为期望 UTF-8 字符串,如下所示:

boost::nowide::nowide_filesystem();

The cause of this issue turned out to be inconsistent use of _ITERATOR_DEBUG_LEVEL .这个问题的原因原来是_ITERATOR_DEBUG_LEVEL使用不一致。 This setting does affect ABI compatibility.此设置确实会影响 ABI 兼容性。 I was setting this flag (to 0) in my own code, but it was not set in the Boost build.我在自己的代码中设置了这个标志(为 0),但它没有在 Boost 版本中设置。 The solution is to either remove the flag from one's own code, or add the flag to the Boost build by adding define=_ITERATOR_DEBUG_LEVEL=0 to the b2 arguments (from another stack overflow answer ).解决方案是从自己的代码中删除标志,或者通过将define=_ITERATOR_DEBUG_LEVEL=0添加到 b2 参数(来自另一个堆栈溢出答案)来将标志添加到 Boost 构建中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM