Assume a simple file bla.cpp
:
struct MyClass {
virtual int foo(int x);
virtual ~MyClass();
};
int MyClass::foo(int x) { return x + 23; }
MyClass::~MyClass() {}
Build into a shared library with
g++ -c -fPIC bla.cpp
g++ -shared -o bla.so bla.o
will usually contain some type_info
symbol because RTTI is enabled by default on gcc. However, if I build with
g++ -c -fPIC -fno-rtti bla.cpp
the type_info
will be missing.
Is there a simple, reliable way (on gcc
or clang
) to check if a library has been built with -fno-rtti
or -frtti
? I ask because today I stared at the infamous undefined reference to type_info
and it took me a moment to understand that this was cause by a library I was linking against being built with -fno-rtti
.
<dynamic_cast>
and see if you get a compilation error? Or do you need to conduct this test during runtime? – Chafeedynamic_cast
my code breaks depending on my setting off(no)rtti
. I'm wondering about a library I'm linking against (here inheritance is usually enough to break compilation). I really want to know this duringconfigure
time to set up parts of my build correctly or perhaps warn about it. – Propel