同时使用2个版本提振 [英] Using concurrently 2 versions of boost

查看:79
本文介绍了同时使用2个版本提振的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用RHEL 5.3,它随GCC 4.1.2和提高1.33。
还有就是一些功能我想,那是缺少升压1.33。
因此,想到的是升级到新的版本提升1.43。


  1. 是否可以同时使用从boost 1.43有的只有头库(S)和1.33的休息吗?比如我想使用unorded_map,这是提升1.33失踪。


  2. 是否有可能同时使用二进制Boost库不同的版本?



解决方案

NO! - 永远不要这样做

这是不可能的,你可能会得到意外的崩溃。

要得到它做正确的唯一方式是使用命名空间重命名:即创建备用
升压版本放在的不同的的命名空间。

BCP的最新版本提供了该选项。所以,你会使用类似boost_1_43,而不是提升。但它会为你相当透明。但你还是应该知道
那你不能使用boost的两个版本同一CPP文件。

也采取这种讨论一下:<一href=\"http://stackoverflow.com/questions/836875/creating-library-with-backward-compatible-abi-that-uses-boost\">http://stackoverflow.com/questions/836875/creating-library-with-backward-compatible-abi-that-uses-boost

该脚本喜欢重命名的命名空间,定义,包括让你真正可以包括两个
升压的版本像

 的#include&LT;升压/ foo.hpp&GT;
#包括LT&; myboost / bar.hpp&GT;提高:: foo的F;
myboost ::杆B;

升压BCP不允许这样做。

但你仍然应该小心一些库导出的externC标志,而不
升压preFIX,提高::螺纹和boost ::正则表达式的C API(regexec,regcomp)

修改

作为例子这种问题创建以下文件:

a.cpp:

 模板&LT; typename的美孚&GT;
富加(foo的,富B)
{
        返回A + B;
}
INT美孚(INT X,int y)对
{
        返回的add(X,Y);
}

b.cpp:

 模板&LT; typename的美孚&GT;
富加(foo的,富B)
{
        返回A-B;
}
INT巴(INT X,int y)对
{
        返回的add(X,Y);
}

TEST.CPP:

 的#include&LT;&iostream的GT;INT美孚(INT,INT);
INT栏(INT,INT);诠释的main()
{
        性病::法院LT&;&LT;富(10,20)LT;&LT;&LT;&LT;杆(10,20)LT;&LT;的std :: ENDL;
}

编译它们:

  G ++ a.cpp b.cpp TEST.CPP

您所期望的:

  30 -10

但你会得到

  30 30

  -10 -10

根据连接顺序。

因此​​,使用两个升压版本中,你可能会意外地使用其它升压和崩溃符号
同在这个程序符号 INT添加&LT;&诠释GT;(INT,INT)甚至解析为同一个符号
如果它被放置在不同的编译单元。

I'm using RHEL 5.3, which is shipped with gcc 4.1.2 and boost 1.33. There're some features I want, that are missing in the boost 1.33. Therefore the thought was to upgrade to fresh boost release 1.43.

  1. Is it possible to use concurrently some header-only library(s) from boost 1.43 and the rest from 1.33? For example I want to use unorded_map, which is missing in boost 1.33.

  2. Is it possible to use concurrently binary boost libraries from different releases?

解决方案

NO -- never do this!

It is impossible, you'll likely to get accidental crashes.

The only way to get it done correctly is using namespace renaming: i.e. create alternative boost version placed in different namespace.

Latest version of BCP provides this option. So you will use something like boost_1_43 instead of boost. But it will be quite transparent for you. But you should still be aware of that you can't use two versions of boost in same cpp file.

Also take a look on this discussion: http://stackoverflow.com/questions/836875/creating-library-with-backward-compatible-abi-that-uses-boost

The liked script renames namespace, defines and includes so you can actually include two versions of boost like

#include <boost/foo.hpp>
#include <myboost/bar.hpp>

boost::foo f;
myboost::bar b;

Boost BCP does not allow this.

But still you should be careful as some libraries export extern "C" symbols without boost prefix, boost::thread and boost::regex's C API (regexec, regcomp)

Edit

As example of such issue create following files:

a.cpp:

template<typename Foo>
Foo add(Foo a, Foo b)
{
        return a+b;
}


int foo(int x,int y)
{
        return add(x,y);
}

b.cpp:

template<typename Foo>
Foo add(Foo a, Foo b)
{
        return a-b;
}


int bar(int x,int y)
{
        return add(x,y);
}

test.cpp:

#include <iostream>

int foo(int,int);
int bar(int,int);

int main()
{
        std::cout<< foo(10,20) <<" " <<bar(10,20) << std::endl;
}

Compile them:

g++ a.cpp b.cpp test.cpp

You would expect:

30 -10

But you'll get

30 30

or

-10 -10

Depending on linking order.

So using two boost versions you may accidentally use symbols from other boost and crash same as in this program symbol int add<int>(int,int) is resolved to same symbol even if it is placed in different compilation units.

这篇关于同时使用2个版本提振的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆