2

我对这段代码有疑问:

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

namespace bfs = boost::filesystem;

int main(int argc, char **argv)
{
    try
    {
        bfs::create_symlink("C:\\Users\\Administrator\\Desktop\\test.txt",
                        "C:\\Users\\Administrator\\Desktop\\test_symlink.txt");
    }
    catch (std::exception& e)
    {
        std::cout << e.what() << std::endl;
    }

    return 0;
}

调用该create_symlink函数会导致与消息一起引发异常:

boost::filesystem::create_directory_symlink: The request is not supported: "C:\\Users\\Administrator\\Desktop\\test.txt", "C:\\Users\\Administrator\\Desktop\\test_symlink.txt"

我浏览了 Boost.Filesystem 的operations.cpp文件,发现了这个:

  BOOST_FILESYSTEM_DECL
  void create_symlink(const path& to, const path& from, error_code* ec)
  {
#   if defined(BOOST_WINDOWS_API) && _WIN32_WINNT < 0x0600  // SDK earlier than Vista and Server 2008
    error(true, error_code(BOOST_ERROR_NOT_SUPPORTED, system_category()), to, from, ec,
      "boost::filesystem::create_directory_symlink");
#   else

#     if defined(BOOST_WINDOWS_API) && _WIN32_WINNT >= 0x0600
        // see if actually supported by Windows runtime dll
        if (error(!create_symbolic_link_api,
            error_code(BOOST_ERROR_NOT_SUPPORTED, system_category()),
            to, from, ec,
            "boost::filesystem::create_symlink"))
          return;
#     endif

    error(!BOOST_CREATE_SYMBOLIC_LINK(from.c_str(), to.c_str(), 0),
      to, from, ec, "boost::filesystem::create_symlink");
#   endif
  }

这表明我_WIN32_WINNT在编译 Boost 时可能不够高。我已经去编译了 Boost.Filesystem ,但是这次define=_WIN32_WINNT=0x601添加了,我仍然得到一个带有相同消息的异常。我还尝试定义BOOST_WINDOWS_API 似乎已弃用但导致编译错误的定义。

我正在使用 Windows 7、Boost 1.54.0 和MinGW-x64-4.8.1-posix-seh-rev4mingw -builds

4

1 回答 1

-1

我不太确定,但我的意思是符号链接仅在 unix 系统上受支持。

于 2013-10-21T08:13:19.273 回答