繁体   English   中英

boost1.44.0文件系统v3无法在solaris sparc 64位平台上正常运行

[英]boost1.44.0 filesystem v3 can not run properly on solaris sparc 64bit platform

我在程序中使用了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时,结果是“ not dir”。

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

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;
}

您可能还需要升级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文件系统实现也没有足够的信心。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM