【问题标题】:Weird behaviour while using boost on different platform/gcc versions在不同平台/gcc 版本上使用 boost 时的奇怪行为
【发布时间】:2013-02-20 05:15:57
【问题描述】:

我正在使用 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(...) 有什么问题?

【问题讨论】:

    标签: c++ boost


    【解决方案1】:

    我会确保您使用的是 boost::filesystem 的第 3 版,这是一个重大变化,包括添加了 canonical()。您可能需要升级您的 boost 安装或define BOOST_FILESYSTEM_VERSION 以获得 V3。

    即使您安装了 boost 1.53,您也需要make sure that your code is being built against it。您的操作系统可能有一个正在使用的默认版本。例如,Debian 挤压存储库(当前稳定版本)在 boost 1.42 上,根本不包含 boost::filesystem V3。

    【讨论】:

    • 谢谢,问题是由 CMake 与操作系统合作选择的不同版本引起的。
    猜你喜欢
    • 1970-01-01
    • 2011-07-17
    • 2021-02-07
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 2011-12-01
    • 2013-11-15
    • 2016-05-08
    相关资源
    最近更新 更多