Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ namespace collision with gtest and boost

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?

like image 315
bias Avatar asked Jul 20 '09 21:07

bias


2 Answers

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.

like image 108
Troubadour Avatar answered Oct 02 '22 07:10

Troubadour


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

like image 39
Jesse Vogt Avatar answered Oct 02 '22 07:10

Jesse Vogt