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

标签 c++ boost googletest

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

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

最佳答案

尝试使用定义的 BOOST_HAS_TR1_TUPLE 进行构建。看起来 boost 和你的 std 库都在定义 std::tr1::tuple 而我看不到如何禁用 std版本。查看 boost header ,虽然它似乎需要定义 BOOST_HAS_TR1_TUPLE 以告诉 boost std::tr1::tuple 已经定义。

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

关于c++ 命名空间与 gtest 和 boost 的冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1156003/

相关文章:

c++ - fork 子程序中要求与启动器程序进行管道通信

c++ - TearDown() 和 Setup() 函数有什么好处?

c++ - 任何从 c++filt demangled 输出中获取更多信息的方式

c++ - boost shared_ptr use_count 函数

c++ - 带有 restclient-cpp 的 JSON 属性树

c++ - 如何在不完全 boost 的情况下使用 boost.xpressive ?

c++ - 是否有适用于 windows 的 "Google Test"( gtest ) 的图形测试运行程序?

c++ - 避免使用 Google Mock 调用基类

c++ - range-v3:调整已经实现迭代器接口(interface)的自定义类(开始/结束)

C++ Win32 未处理的异常处理程序