【问题标题】:C++ project Compatibility with multiple versions of boostC++项目与boost多个版本的兼容性
【发布时间】:2012-06-11 18:28:08
【问题描述】:

我正在开发一个 C++ 项目,并进行了一些更改以使其与 boost 1.46(突触安装在 Oneiric 上的默认版本)兼容,但我还想让它与旧版本正确编译的提升。 如何根据正在使用的版本提升有不同的代码。是否配置文件(由 autoconf 生成)#DEFINE 一些变量来指示哪个?另外,我不完全确定在哪个版本中引入了这个特定的变化。

这是我要集成的两个版本的差异,基于 boost 版本:

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 不是很熟悉,这不是我的代码,是别人的。任何对这里发生的事情的解释将不胜感激。

谢谢

【问题讨论】:

    标签: c++ boost backwards-compatibility autoconf boost-filesystem


    【解决方案1】:

    使用 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
    

    【讨论】:

    【解决方案2】:

    Boost 具有“version.hpp”,其中包含可用于区分不同版本的 boost 定义。 header 本身对此进行了解释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-20
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-22
      相关资源
      最近更新 更多