Project with no RTTI

609 views
Skip to first unread message

guile

unread,
Jun 3, 2009, 3:48:21 PM6/3/09
to Google C++ Testing Framework
My c++ project compiles with the flag -fno-rtti set (the development
is made under MacOS X with XCode).

When I compile the tests, I got the following error: "error: cannot
use typeid with -fno-rtti"

I also defined the variable GTEST_HAS_RTTI to 0 to disable the RTTI.

What is missing in my project configuration ?

Zhanyong Wan (λx.x x)

unread,
Jun 3, 2009, 4:14:58 PM6/3/09
to guile, Google C++ Testing Framework
On Wed, Jun 3, 2009 at 12:48 PM, guile <four...@gmail.com> wrote:
>
> My c++ project compiles with the flag -fno-rtti set (the development
> is made under MacOS X with XCode).
>
> When I compile the tests, I got the following error: "error: cannot
> use typeid with -fno-rtti"
>
> I also defined the variable GTEST_HAS_RTTI to 0 to disable the RTTI.

Which version of gtest are you using? Can you find GTEST_HAS_RTTI in
include/gtest/internal/gtest-port.h?

>
> What is missing in my project configuration ?
>

--
Zhanyong

guile

unread,
Jun 3, 2009, 4:34:19 PM6/3/09
to Google C++ Testing Framework
I use the "trunk" version (recompiled).
I can find the GTEST_HAS_RTTI in the header file you specified.


On 3 juin, 22:14, Zhanyong Wan (λx.x x) <w...@google.com> wrote:

Zhanyong Wan (λx.x x)

unread,
Jun 3, 2009, 4:37:44 PM6/3/09
to guile, Google C++ Testing Framework
On Wed, Jun 3, 2009 at 1:34 PM, guile <four...@gmail.com> wrote:
>
>
> I use the "trunk" version (recompiled).
> I can find the GTEST_HAS_RTTI in the header file you specified.

How did you set GTEST_HAS_RTTI to 0? Was the setting applied to the
tests you were compiling? What is the exact error message?

>
> On 3 juin, 22:14, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
>> On Wed, Jun 3, 2009 at 12:48 PM, guile <fourni...@gmail.com> wrote:
>>
>> > My c++ project compiles with the flag -fno-rtti set (the development
>> > is made under MacOS X with XCode).
>>
>> > When I compile the tests, I got the following error: "error: cannot
>> > use typeid with -fno-rtti"
>>
>> > I also defined the variable GTEST_HAS_RTTI to 0 to disable the RTTI.
>>
>> Which version of gtest are you using?  Can you find GTEST_HAS_RTTI in
>> include/gtest/internal/gtest-port.h?
>>
>>
>>
>> > What is missing in my project configuration ?
>>
>> --
>> Zhanyong
>

--
Zhanyong

guile

unread,
Jun 3, 2009, 5:50:17 PM6/3/09
to Google C++ Testing Framework
I passed the option -DGTEST_HAS_RTTI=0 to gcc and I also put a
"#define GTEST_HAS_RTTI 0" line in the file I am compiling.

The error message returned by the compiler is:
"error: cannot use typeid with -fno-rtti"



On 3 juin, 22:37, Zhanyong Wan (λx.x x) <w...@google.com> wrote:

Zhanyong Wan (λx.x x)

unread,
Jun 3, 2009, 5:53:45 PM6/3/09
to guile, Google C++ Testing Framework
On Wed, Jun 3, 2009 at 2:50 PM, guile <four...@gmail.com> wrote:
>
>
> I passed the option -DGTEST_HAS_RTTI=0 to gcc and I also put a
> "#define GTEST_HAS_RTTI 0" line in the file I am compiling.
>
> The error message returned by the compiler is:
> "error: cannot use typeid with -fno-rtti"

Is the error in gtest's code or your code? Could you please provide
the source code that triggers this error and let's know which line
caused the error?

>
>
>
> On 3 juin, 22:37, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
>> On Wed, Jun 3, 2009 at 1:34 PM, guile <fourni...@gmail.com> wrote:
>>
>> > I use the "trunk" version (recompiled).
>> > I can find the GTEST_HAS_RTTI in the header file you specified.
>>
>> How did you set GTEST_HAS_RTTI to 0?  Was the setting applied to the
>> tests you were compiling?  What is the exact error message?
>>
>>
>>
>>
>>
>> > On 3 juin, 22:14, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
>> >> On Wed, Jun 3, 2009 at 12:48 PM, guile <fourni...@gmail.com> wrote:
>>
>> >> > My c++ project compiles with the flag -fno-rtti set (the development
>> >> > is made under MacOS X with XCode).
>>
>> >> > When I compile the tests, I got the following error: "error: cannot
>> >> > use typeid with -fno-rtti"
>>
>> >> > I also defined the variable GTEST_HAS_RTTI to 0 to disable the RTTI.
>>
>> >> Which version of gtest are you using?  Can you find GTEST_HAS_RTTI in
>> >> include/gtest/internal/gtest-port.h?
>>
>> >> > What is missing in my project configuration ?
>>
>> >> --
>> >> Zhanyong
>>
>> --
>> Zhanyong
>

--
Zhanyong

guile

unread,
Jun 3, 2009, 5:57:30 PM6/3/09
to Google C++ Testing Framework
Here's the code that is failing:

/* main.cc */

#define GTEST_HAS_RTTI 0
#include <gtest/gtest.h>

#if GTEST_HAS_RTTI
#error Gtest should not have RTTI enabled
#endif

/*
int main(int argc, char **argv)
{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
*/


It's just the include of gtest header file that is failing.

The errors come from the following standard header files:
functional
functional_iterate.h



On 3 juin, 23:53, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
Message has been deleted

guile

unread,
Jun 3, 2009, 6:00:47 PM6/3/09
to Google C++ Testing Framework
Here's a more detailed error log:

77%] Building CXX object test/CMakeFiles/test.dir/TestSuite.cpp.o
/usr/include/c++/4.0.0/tr1/functional: In static member function
‘static bool
std::tr1::_Function_base::_Base_manager<_Functor>::_M_manager
(std::tr1::_Any_data&, const std::tr1::_Any_data&,
std::tr1::_Manager_operation)’:
/usr/include/c++/4.0.0/tr1/functional:899: error: cannot use typeid
with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional: In static member function
‘static bool
std::tr1::_Function_base::_Ref_manager<_Functor>::_M_manager
(std::tr1::_Any_data&, const std::tr1::_Any_data&,
std::tr1::_Manager_operation)’:
/usr/include/c++/4.0.0/tr1/functional:977: error: cannot use typeid
with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In static member
function ‘static bool std::tr1::_Function_handler<void ()(), _Member
_Class::*>::_M_manager(std::tr1::_Any_data&, const
std::tr1::_Any_data&, std::tr1::_Manager_operation)’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:572: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘const std::type_info& std::tr1::function<_Res ()()>::target_type()
const’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:883: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘_Functor* std::tr1::function<_Res ()()>::target()’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:892: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘const _Functor* std::tr1::function<_Res ()()>::target() const’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:912: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In static member
function ‘static bool std::tr1::_Function_handler<void ()(_T1),
_Member _Class::*>::_M_manager(std::tr1::_Any_data&, const
std::tr1::_Any_data&, std::tr1::_Manager_operation)’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:572: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘const std::type_info& std::tr1::function<_Res ()(_T1)>::target_type()
const’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:883: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘_Functor* std::tr1::function<_Res ()(_T1)>::target()’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:892: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘const _Functor* std::tr1::function<_Res ()(_T1)>::target() const’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:912: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In static member
function ‘static bool std::tr1::_Function_handler<void ()(_T1, _T2),
_Member _Class::*>::_M_manager(std::tr1::_Any_data&, const
std::tr1::_Any_data&, std::tr1::_Manager_operation)’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:572: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘const std::type_info& std::tr1::function<_Res ()(_T1, _T2)
>::target_type() const’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:883: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘_Functor* std::tr1::function<_Res ()(_T1, _T2)>::target()’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:892: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘const _Functor* std::tr1::function<_Res ()(_T1, _T2)>::target()
const’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:912: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In static member
function ‘static bool std::tr1::_Function_handler<void ()(_T1, _T2,
_T3), _Member _Class::*>::_M_manager(std::tr1::_Any_data&, const
std::tr1::_Any_data&, std::tr1::_Manager_operation)’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:572: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘const std::type_info& std::tr1::function<_Res ()(_T1, _T2, _T3)
>::target_type() const’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:883: error: cannot use
typeid with -fno-rtti
/usr/include/c++/4.0.0/tr1/functional_iterate.h: In member function
‘_Functor* std::tr1::function<_Res ()(_T1, _T2, _T3)>::target()’:
/usr/include/c++/4.0.0/tr1/functional_iterate.h:892: error: cannot use
typeid with -fno-rtti

Zhanyong Wan (λx.x x)

unread,
Jun 3, 2009, 6:09:56 PM6/3/09
to guile, Google C++ Testing Framework
I think you ran into a bug in the version of gcc used in Xcode, namely
that tr1/functional doesn't work with -fno-rtti (it should).

gtest doesn't use tr1/functional. However, its Combine() function
(for value-parameterized tests) use tr1/tuple, whose implementation
happens to pull in tr1/functional (that's how gcc implements it).

I think you can workaround the problem by preventing gtest from
including tr1/tuple. The only functionality you'll lose is Combine(),
which is rarely needed. To do that, just define GTEST_HAS_TR1_TUPLE
to 0. Please let me know if that works.

If this indeed fixes it, we can add logic to gtest to do this
automatically.

--
Zhanyong

Zhanyong Wan (λx.x x)

unread,
Jun 3, 2009, 6:18:53 PM6/3/09
to guile, Google C++ Testing Framework
I opened http://code.google.com/p/googletest/issues/detail?id=153 to track this.

2009/6/3 Zhanyong Wan (λx.x x) <w...@google.com>:

--
Zhanyong

guile

unread,
Jun 4, 2009, 2:18:48 PM6/4/09
to Google C++ Testing Framework
Ok Thanks,
I added the -DGTEST_HAS_TR1_TUPLE=0 to the compiler options and it now
works.



On 4 juin, 00:18, Zhanyong Wan (λx.x x) <w...@google.com> wrote:
> I openedhttp://code.google.com/p/googletest/issues/detail?id=153to track this.
>
> 2009/6/3 Zhanyong Wan (λx.x x) <w...@google.com>:
>
>
>
> > I think you ran into a bug in the version of gcc used in Xcode, namely
> > that tr1/functional doesn't work with -fno-rtti (it should).
>
> > gtest doesn't use tr1/functional.  However, its Combine() function
> > (for value-parameterized tests) use tr1/tuple, whose implementation
> > happens to pull in tr1/functional (that's how gcc implements it).
>
> > I think you can workaround the problem by preventing gtest from
> > including tr1/tuple.  The only functionality you'll lose is Combine(),
> > which is rarely needed.  To do that, just define GTEST_HAS_TR1_TUPLE
> > to 0.  Please let me know if that works.
>
> > If this indeed fixes it, we can add logic to gtest to do this
> > automatically.
>
Reply all
Reply to author
Forward
0 new messages