如果我同时包含 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
如何防止这两个库命名空间发生冲突?
答案 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
。