簡體   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