【问题标题】:boost1.44.0 filesystem v3 can not run properly on solaris sparc 64bit platformboost1.44.0 文件系统 v3 无法在 solaris sparc 64bit 平台上正常运行
【发布时间】:2015-10-16 08:17:20
【问题描述】:

我在我的程序中使用了boost::filesystem::is_directory(),问题是当我使用选项-DBOOST_FILESYSTEM_VERSION=3 编译我的程序时,程序无法正常运行。 boost 版本是 1.44.0。

具体来说,我通过以下命令构建文件系统库:

./bjam --toolset=gcc define=BOOST_FILESYSTEM_VERSION=3 --with-filesystem stage 

我用这样的命令构建我的程序。

g++ -I boost_1_44_0_folder test.cpp -o test boost_1_44_0_folder/stage/lib/libboost_filesystem.a boost_1_44_0_folder/stage/lib/libboost_system.a -DBOOST_FILESYSTEM_VERSION=3

当我执行./test时,结果是“不是目录”。

但是如果我用这样的命令构建我的程序。

g++ -I boost_1_44_0_folder test.cpp -o test boost_1_44_0_folder/stage/lib/libboost_filesystem.a boost_1_44_0_folder/stage/lib/libboost_system.a

当我执行 ./test 时,结果是“is dir”。

而我的测试代码如下所示。

test.cpp

#include <boost/filesystem.hpp>
#include <iostream>
using namespace std;
int main() {
    namespace bf = boost::filesystem;
    bf::path p("/home");
    if (!boost::filesystem::is_directory(p)) {
        cout << "is not dir" << endl;
    } else {
        cout << "is dir" << endl;
    }
    return 0;
}

【问题讨论】:

  • /home 是目录吗?是符号链接吗?挂载点?
  • 其他目录也一样。
  • 您使用的是哪个 GCC 版本? Boost 将突破几乎所有 C++ 编译器的极限,而 Oracle 随 Solaris 提供的版本往往有点过时。 (如果您使用的是 Sun 提供的 Solaris 版本,那它确实过时了......)

标签: c++ gcc boost filesystems solaris


【解决方案1】:

您可能还需要升级您的 Boost 版本。如果查看源代码(例如:http://svn.boost.org/svn/boost/trunk/boost/wave/util/filesystem_compatibility.hpp),1.0.46 和 1.0.50 版本的文件系统处理有很多变化,很多代码看起来像这样:

#if BOOST_FILESYSTEM_VERSION >= 3
#if BOOST_VERSION >= 105000
        return boost::filesystem::complete(p, base);
#else
        return boost::filesystem3::complete(p, base);
#endif
#else
        return boost::filesystem::complete(p, base);
#endif

FWIW,operations.cpp (http://svn.boost.org/svn/boost/trunk/libs/filesystem/src/operations.cpp) 中的这段代码真的让我很困扰:

// both stats now known to be valid
return  s1.st_dev == s2.st_dev && s1.st_ino == s2.st_ino
    // According to the POSIX stat specs, "The st_ino and st_dev fields
    // taken together uniquely identify the file within the system."
    // Just to be sure, size and mod time are also checked.
    && s1.st_size == s2.st_size && s1.st_mtime == s2.st_mtime;

因此,如果您使用 Boost 检查两个文件是否实际上是同一个文件,并且它们确实是同一个文件,但它在错误的时刻被写入或什至只是 touch'd,Boost 将返回文件本身不是。除了不能正确识别像简单目录这样常见的东西之外,我对 Boost 文件系统实现的其余部分也没有信心。

【讨论】:

  • 您好安德鲁,感谢您的回答。我想我已经找到了根本原因。这是 boost 1.44.0 文件系统 v3 的一个错误。您可能会看到票 #5355。 svn.boost.org/trac/boost/ticket/5355
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-10
  • 1970-01-01
  • 2013-05-31
  • 1970-01-01
相关资源
最近更新 更多