简体   繁体   English

C ++项目与Boost的多个版本的兼容性

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

I'm working on a C++ project and I made a couple changes to make it compatible with boost 1.46 (the default version that synaptic installs on Oneiric), but I'd like to also make it compile correctly with the old version of boost. 我正在开发一个C ++项目,并进行了一些更改以使其与boost 1.46(Oneiric上突触安装的默认版本)兼容,但我也想使其与旧版本的boost一起正确编译。 How can I have different code based on the version boost being used. 基于所使用的版本提升,如何拥有不同的代码。 Does the configure file (generated by autoconf) #DEFINE some variable to indicate which one? (由autoconf生成的)配置文件#DEFINE是否有一些变量指示哪个变量? Also, I'm not entirely sure which version where this particular change was introduced. 另外,我不确定要在哪个版本中引入此特定更改。

Here's the diff for the two versions I want to integrate, based on boost version: 这是我要集成的两个版本(基于增强版)的差异:

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;

I'm not very familiar with autoconf and this isn't my code, it's someone else's. 我对autoconf不太熟悉,这不是我的代码,而是别人的代码。 Any explanation of what's going on here would be appreciated. 对此的任何解释将不胜感激。

Thanks 谢谢

Boost has 'version.hpp', which contains defines you could use to differentiate between the various versions of boost. Boost具有'version.hpp',其中包含一些定义,您可以用来区分boost的各个版本。 It's explained in the header itself. 标题本身中进行了说明。

Conditional compilation with the Boost version number: 使用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