C/C++ Headsup: Compiling C++ code with GCC while linking against system libraries that use RTTI

ekvz

Well-Known Member

Reaction score: 278
Messages: 431

While it seems that GCC and Clang get along fairly well even when linking against C++ code build with the opposing compiler they don't seem to agree on RTTI (which is mostly used to implement dynamic_cast i think). So when the application compiled with g++ calls into a system library (likely build by Clang) that tries to do a dynamic cast it will crash at a position kind of like this:

Code:
Program received signal SIGSEGV, Segmentation fault.
0x0000000802efba18 in vtable for __cxxabiv1::__si_class_type_info () from /lib/libcxxrt.so.1

The only way to fix this seems to tell GCC to use Clangs C++ library and headers by using the following flags:

Code:
CXXFLAGS+=-nostdinc -nostdinc++ -I/usr/include/c++/v1 -I/usr/include -I/usr/local/include

Code:
LDFLAGS+=-nodefaultlibs -lc++ -lcxxrt -lthr -lm -lc -lgcc_s

If your application uses intrinsics you need to add the appropriate GCC header files to the search path though as GCC will bark when trying to use Clangs intrinsic headers:

Code:
CXXFLAG+S=-I/usr/local/lib/gcc9/gcc/x86_64-portbld-freebsd12.1/9.3.0/include

Obviously you need to adjust that path to include the appropriate versions and architecture.

Hope that saves someone a bit of time debugging.
 

gutiersa

Member

Reaction score: 8
Messages: 97

Hello, I am getting something similar for months. Now my server is down because I am unable to renew my certificates with certbot (the let'sencrypt free service) This is the error I am getting.

Code:
* ob
object  : <refcnt 0 at 0x802d13ba0>
type    : str
refcount: 0
address : 0x802d13ba0
* op->_ob_prev->_ob_next
object  : <refcnt 0 at 0x802d13b9f>Segmentation fault

However, everything you have written up there, I don't understand. I am a non programmer.

Thanks so much. Any input will help.
 
OP
E

ekvz

Well-Known Member

Reaction score: 278
Messages: 431

I am sorry to say this but your problem is likely unrelated to the one described here. In any case what is the application that is giving you this error and how was it obtained (mostly in relation to if it was indeed compiled with gcc)?
 
Top