6

如果我同时包含gtest/gtest.hboost/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

4 回答 4

10

尝试使用BOOST_HAS_TR1_TUPLE定义构建。看起来 boost 和您的std库都在定义std::tr1::tuple,我看不到如何禁用该std版本。虽然看起来BOOST_HAS_TR1_TUPLE需要定义 boost 标头来告诉 booststd::tr1::tuple已经定义了。

当我尝试编译包含这两个头文件的文件时,我遇到了与您类似的错误,然后当我定义BOOST_HAS_TR1_TUPLE.

于 2009-07-20T22:23:40.203 回答
2

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

于 2009-07-20T21:27:46.277 回答
2

使用 gtest 在 gtest.h 中将 GTEST_HAS_TR1_TUPLE 设置为 0 对我有帮助

于 2012-09-22T08:58:39.973 回答
1

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

于 2011-06-10T17:16:16.637 回答