c++ - 在不同平台/gcc 版本上使用 boost 时出现奇怪的行为

标签 c++ boost

我正在使用 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/

相关文章:

c++ - string to flyweights 的字符串转换 : Better performance option

c++ - 使用 Boost 序列化时如何删除此重复代码?

c++ - Borland C++ Typecast overrides - 为什么歧义?

c++ - 为什么默认构造函数不适用于 `vector::emplace_back`

c++ - 了解基类初始化

c++ - 设置自定义图标

c++ - 将 vector 或参数传递给 boost::process (boost::fusion)

c++ - Python 的 C++ 发布订阅/观察者模式?

c++ - union 中的 boost::optional<>?

c++ - 树上的多线程