我遇到这段代码的问题:
#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
}
这表明在编译Boost时我的_WIN32_WINNT
可能不够高。我已经再次编译了Boost.Filesystem,但这次添加了define=_WIN32_WINNT=0x601
,我仍然得到一个带有相同消息的异常。我也尝试过定义BOOST_WINDOWS_API
which seems to be deprecated,但这会导致编译错误。
我在mingw-builds使用Windows 7,Boost 1.54.0和MinGW-x64-4.8.1-posix-seh-rev4
。
答案 0 :(得分:-1)
我不太确定,但我的意思是只在unix系统上支持符号链接。