3

我已经构建了一个依赖于多个 Boost 库的库(VC10)。我想在多个应用程序中使用这个库,其中每个应用程序都依赖于不同的 Boost 版本,我希望能够在不为每个 Boost 版本构建库的情况下做到这一点。

我已经使用 BOOST_ALL_DYN_LINK 以及 BOOST_ALL_NO_LIB 构建了我的库,但这两个库似乎都依赖于特定的 Boost 版本。

有人可以解释一下我如何构建一个依赖于 Boost 的库,可以在不重新编译或重新链接库的情况下更新 Boost 版本吗?

4

1 回答 1

1

“有人能解释一下我如何构建一个依赖于 Boost 的库,可以在不重新编译或重新链接库的情况下更新 Boost 版本吗?”

我不认为这是可能的。任何数量的小更改,例如向类添加新数据成员,都需要重新编译以在版本之间切换。只有当 boost 在版本之间不更改任何此类细节时,才有可能。

如果您无法遵循 @jamesj 坚持使用单一版本的建议,命名空间可能会有所帮助。我会采用每个 boost 版本并对其进行修改,以便将 boost_x_y_z 作为顶级命名空间而不是 boost_x_y_z,其中 xyz 给出了版本号。所以下面的代码

namespace acc = boost::accumulators;
typedef acc::features<acc::tag::density> features_t;
typedef acc::accumulator_set<double, features_t> accumulator_t;

可以针对版本 1.47.0:

namespace acc = boost_1_47_0::accumulators;
typedef acc::features<acc::tag::density> features_t;
typedef acc::accumulator_set<double, features_t> accumulator_t;

如果您不在乎使用什么版本,您可以在某处放置标题:

namespace boost_latest = boost_1_50_0;

所以我的例子会变成:

namespace acc = boost_latest::accumulators;
typedef acc::features<acc::tag::density> features_t;
typedef acc::accumulator_set<double, features_t> accumulator_t;

然后当一个新版本出现时,您只需更新一个定义并重新编译。您的库的新版本仍应与旧程序的 ABI 兼容。但是他们不会在不重新编译的情况下利用新的 boost 版本。

于 2012-07-06T05:33:46.060 回答