簡體   English   中英

C ++項目與Boost的多個版本的兼容性

[英]C++ project Compatibility with multiple versions of boost

我正在開發一個C ++項目,並進行了一些更改以使其與boost 1.46(Oneiric上突觸安裝的默認版本)兼容,但我也想使其與舊版本的boost一起正確編譯。 基於所使用的版本提升,如何擁有不同的代碼。 (由autoconf生成的)配置文件#DEFINE是否有一些變量指示哪個變量? 另外,我不確定要在哪個版本中引入此特定更改。

這是我要集成的兩個版本(基於增強版)的差異:

diff --git a/src/util/Misc.cpp b/src/util/Misc.cpp
index 467144d..a9738aa 100644
--- a/src/util/Misc.cpp
+++ b/src/util/Misc.cpp
@@ -28,7 +28,7 @@ void MiscUtil::FindProgramDir(int argc, char* argv[])
 {
     if (argc == 0 || argv == 0)
         return;
-    programDir = path(argv[0], native).branch_path();
+    programDir = path(argv[0]).branch_path();
 }

 void MiscUtil::WordToBytes(unsigned word, byte* out)
@@ -70,7 +70,7 @@ std::string MiscUtil::OpenFile(std::string name, std::ifstream& f)
     {
         path p = programDir / name;
         p.normalize();
-        programDirFile = p.native_file_string();
+        programDirFile = p.string();
         f.open(programDirFile.c_str());
         if (f.is_open())
             return programDirFile;
@@ -78,7 +78,7 @@ std::string MiscUtil::OpenFile(std::string name, std::ifstream& f)
     {
         path p = boost::filesystem::path(ABS_TOP_SRCDIR) / "share" / name;
         p.normalize();
-        absFile = p.native_file_string();
+        absFile = p.string();
         f.open(absFile.c_str());
         if (f.is_open())
             return absFile;
@@ -86,7 +86,7 @@ std::string MiscUtil::OpenFile(std::string name, std::ifstream& f)
     {
         path p = boost::filesystem::path(DATADIR) / name;
         p.normalize();
-        dataFile = p.native_file_string();
+        dataFile = p.string();
         f.open(dataFile.c_str());
         if (f.is_open())
             return dataFile;

我對autoconf不太熟悉,這不是我的代碼,而是別人的代碼。 對此的任何解釋將不勝感激。

謝謝

Boost具有'version.hpp',其中包含一些定義,您可以用來區分boost的各個版本。 標題本身中進行了說明。

使用Boost版本號的條件編譯:

#include <boost/version.hpp>

#if BOOST_VERSION / 100 % 1000 == 46
// 1.46 version
    programDir = path(argv[0], native).branch_path();
#else
// older version
    programDir = path(argv[0]).branch_path();
#endif

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM