我对这段代码有疑问:
#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-rev4
mingw -builds。