I want to explore how to link a C ++ program without libstdC ++, but with rtti support. I tried to compile it as described below. Any necessary but missing character that I can define as the strcmp function in the example, but is it possible to define characters like info without explicit magic / sorcery? And if possible, how?
cd /tmp && cat << 'eof' >rtti.cpp && g++ -nodefaultlibs -lc rtti.cpp
extern "C" int strcmp(const char *s1, const char *s2) { return 0; }; #include "typeinfo" int main(){ return typeid(int) == typeid(char); }
Linker says:
/tmp/cc6rBAef.o: In the `main 'function:
rtti.cpp:(.text+0x18): undefined reference to `typeinfo for char' rtti.cpp:(.text+0x1d): undefined reference to `typeinfo for int' collect2: error: ld returned 1 exit status
So, how can I define 'typeinfo from char' (_ ZTIc @@ CXXABI_1.3) in the source file using g ++ or clang ++?
PS. Do not ask me why I need this. Just curiosity.
source share