c++ 与 gtest 和 boost 的命名空间冲突
如果我同时包含 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
如何防止这两个库命名空间发生冲突?
If I include both gtest/gtest.h and boost/math/distributions/poisson.hpp I get
/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
How do I prevent these two library namespaces from colliding?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试使用定义的
BOOST_HAS_TR1_TUPLE
进行构建。 看起来 boost 和您的std
库都在定义std::tr1::tuple
并且我不知道如何禁用std
版本。 查看 boost 标头,似乎需要定义BOOST_HAS_TR1_TUPLE
来告诉 booststd::tr1::tuple
已经定义。当我尝试编译包含这两个标头的文件时,我遇到了与您类似的错误,然后当我定义
BOOST_HAS_TR1_TUPLE
时,它们消失了。Try building with
BOOST_HAS_TR1_TUPLE
defined. It looks like both boost and yourstd
libraries are definingstd::tr1::tuple
and I can't see how to disable thestd
version. Looking at the boost header though it appears thatBOOST_HAS_TR1_TUPLE
needs to be defined to tell boost thatstd::tr1::tuple
is already defined.I got similar errors to yours when I tried to compile a file including both those headers and then they disappeared when I defined
BOOST_HAS_TR1_TUPLE
.您是否尝试过切换包含的顺序? 其他头文件可能会更优雅地处理事情。
Have you tried switching the order of the includes? It is possible the other header file handles things a little more gracefully.
在 gtest.h 中将 gtest 设置 GTEST_HAS_TR1_TUPLE 为 0 对我的情况有帮助
With gtest setting GTEST_HAS_TR1_TUPLE to 0 in gtest.h helped in my case
为了能够在 Microsoft Visual Studio 2010 中包含 boost/math/distributions/fisher_f.hpp,
我需要定义
BOOST_NO_0X_HDR_TUPLE
以及BOOST_HAS_TR1_TUPLE
。To be able to include boost/math/distributions/fisher_f.hpp in Microsoft Visual Studio 2010,
I needed to define
BOOST_NO_0X_HDR_TUPLE
as well asBOOST_HAS_TR1_TUPLE
.