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

发布于 2024-07-27 13:56:10 字数 1428 浏览 5 评论 0原文

如果我同时包含 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

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

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

失退 2024-08-03 13:56:10

尝试使用定义的 BOOST_HAS_TR1_TUPLE 进行构建。 看起来 boost 和您的 std 库都在定义 std::tr1::tuple 并且我不知道如何禁用 std版本。 查看 boost 标头,似乎需要定义 BOOST_HAS_TR1_TUPLE 来告诉 boost std::tr1::tuple 已经定义。

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

Try building with BOOST_HAS_TR1_TUPLE defined. It looks like both boost and your std libraries are defining std::tr1::tuple and I can't see how to disable the std version. Looking at the boost header though it appears that BOOST_HAS_TR1_TUPLE needs to be defined to tell boost that std::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.

ˉ厌 2024-08-03 13:56:10

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

Have you tried switching the order of the includes? It is possible the other header file handles things a little more gracefully.

沧笙踏歌 2024-08-03 13:56:10

在 gtest.h 中将 gtest 设置 GTEST_HAS_TR1_TUPLE 为 0 对我的情况有帮助

With gtest setting GTEST_HAS_TR1_TUPLE to 0 in gtest.h helped in my case

青瓷清茶倾城歌 2024-08-03 13:56:10

为了能够在 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 as BOOST_HAS_TR1_TUPLE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文