gpt4 book ai didi

c++ - 不支持 boost::filesystem::create_symlink

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:03:22 24 4
gpt4 key购买 nike

这段代码有问题:

#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 which seems to be deprecated但这导致了编译错误。

我正在使用 Windows 7、Boost 1.54.0 和来自 mingw-buildsMinGW-x64-4.8.1-posix-seh-rev4 .

最佳答案

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

关于c++ - 不支持 boost::filesystem::create_symlink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19471266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com