c ++命名空间与gtest和boost冲突

时间:2009-07-20 21:18:06

标签: c++ boost googletest

如果我同时包含 gtest / gtest.h boost / math / distributions / poisson.hpp

/opt/local/include/boost/tr1/tuple.hpp:63: error: ‘tuple’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:67: error: ‘make_tuple’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:68: error: ‘tie’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:72: error: ‘tuple_size’ is already declared in this scope
/opt/local/include/boost/tr1/tuple.hpp:73: error: ‘tuple_element’ is already declared in this scope

如何防止这两个库命名空间发生冲突?

4 个答案:

答案 0 :(得分:10)

尝试使用BOOST_HAS_TR1_TUPLE定义构建。它看起来像是boost和std库正在定义std::tr1::tuple,我看不到如何禁用std版本。查看boost标题虽然看起来需要定义BOOST_HAS_TR1_TUPLE来告诉我std::tr1::tuple已被定义。

当我尝试编译包含这些标题的文件时,我遇到了类似的错误,然后在我定义BOOST_HAS_TR1_TUPLE时它们就消失了。

答案 1 :(得分:2)

您是否尝试过切换包含的顺序?另一个头文件可能会更优雅地处理事情。

答案 2 :(得分:2)

gtest中的gtest设置GTEST_HAS_TR1_TUPLE为0,在我的情况下有帮助

答案 3 :(得分:1)

为了能够在Microsoft Visual Studio 2010中包含boost / math / distributions / fisher_f.hpp, 我需要定义BOOST_NO_0X_HDR_TUPLE以及BOOST_HAS_TR1_TUPLE