我正在使用 Boost 库实现一个程序。该程序是在不同平台上编译的。我在 Mac OS 上没有问题。
相同的代码在不同的平台上会产生编译器错误。编译器不同:在 Mac OS 上我使用 gcc 4.2,在 Linux gcc 4.4 上,...
但是,有些错误很难解释。
我正在使用 Boost 1.5.3。例如,我收到这条奇怪的消息:
In member function 'std::vector<std::basic_string<char, std::char_traits<char>,
std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>,
std::allocator<char> > > >* FolderReader::get_filenames()':
/home/u/projects/prj/src/batch/folderreader.cpp:119: error:
'canonical' is not a member of 'bf'
其中 bf 定义为 namespace bf = boost::filesystem;
和 canonical()
以这种方式调用:bf::canonical(pp).string()
with pp
set:
for(bf::directory_iterator it = bf::directory_iterator(p); it != bf::directory_iterator(); it++) {
bf::path pp = *it;
...
但是,它应该根据这里的 API 工作: http://www.boost.org/doc/libs/1_53_0/libs/filesystem/doc/reference.html#canonical
注意: 我刚刚更正的其他一些错误属于此类。我必须写:
obj.method1().method2()
作为
class2 &obj2 = obj.method1();
obj2.method2();
否则我会收到一条错误消息。
所以...我对 boost::filesystem::canonical(...)
的调用有什么问题?
最佳答案
我会确保您使用的是 boost::filesystem
的第 3 版,这是一个重大变化,包括添加了 canonical()
。您可能需要升级您的 boost 安装或 define BOOST_FILESYSTEM_VERSION获得V3。
即使您安装了 boost 1.53,您也需要 make sure that your code is being built against it .您的操作系统可能有一个正在使用的默认版本。例如,Debian squeeze 存储库(当前的稳定版本)在 boost 1.42 上,它根本不包含 boost::filesystem
V3。
关于c++ - 在不同平台/gcc 版本上使用 boost 时出现奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15229990/