【问题标题】:boost filesystem suprious errors (temp_directory_path returns <Bad Ptr>)提升文件系统异常错误(temp_directory_path 返回 <Bad Ptr>)
【发布时间】:2014-03-12 15:22:12
【问题描述】:

我正在尝试使用 Boost 获取当前的临时文件夹:

boost::system::error_code error;
auto tmp_path = boost::filesystem::temp_directory_path(error);

if (boost::system::errc::success != error.value())
{
    std::cout << error.message() << std::endl;
}

在 Visual Studio 2013 调试会话期间调查 tmp_path 的值时,似乎 tmp_path 的值不正确 - VS 显示 {m_pathname=&lt;Bad Ptr&gt;}

以下代码也失败,出现异常“字符串太长”,这可能与问题有关:

std::string tmp_file_str("test");
boost::filesystem::path tmp_file(tmp_file_str);

Boost 是使用 msvc 工具集在本地重新编译的:

cd boost-folder
bootstrap
.\b2 toolset=msvc-12.0 variant=release link=static,shared threading=multi --with-chrono --with-date_time --with-filesystem --with-system --with-thread --with-test

环境:

  • Windows 8.1 版本 6.3.9600 Build 9600 x64
  • Visual Studio 2013 版本 12.0.30110.00 更新 1

【问题讨论】:

    标签: c++ windows boost boost-filesystem


    【解决方案1】:

    错误的发生是由于两个因素的巧合:

    • 动态链接且不自动加载的增强库 (BOOST_ALL_DYN_LINK;BOOST_ALL_NO_LIB)
    • 链接的 boost 库处于发布模式,但项目处于调试模式

    使用variant=release,debug 重新编译boost,在链接器属性中指定-gd- 库并将-gd- dll 添加到路径中解决了该问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-14
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      相关资源
      最近更新 更多