作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
这段代码有问题:
#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-builds 的 MinGW-x64-4.8.1-posix-seh-rev4
.
最佳答案
我不太确定,但我的意思是符号链接(symbolic link)仅在 unix 系统上受支持。
关于c++ - 不支持 boost::filesystem::create_symlink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19471266/
我有一个宏来创建链接 makeLink($BUILD_ROOT/lib somewhere/somelibrary.so makelinks) 这样做的目的是使一个完整的构建包含一个类似于开发人员安装
这段代码有问题: #include #include namespace bfs = boost::filesystem; int main(int argc, char **argv) {
我是一名优秀的程序员,十分优秀!