Page 1 of 1
C++ global object with destructor link error: __dso_handle
Posted: Sat Feb 25, 2012 10:03 am
by vitaly
Hello!
I try to compile simple C++ program. Eventually I reduced it to:
Code: Select all
class CD {
public:
~CD(){x=0;}
int x;
};
CD cd;
which gives me the error:
Compiling ../tmp/1.cpp
Linking build/ch.elf
build/obj/1.o: In function `__static_initialization_and_destruction_0':
.../chibios/../tmp/1.cpp:7: undefined reference to `__dso_handle'
collect2: ld returned 1 exit status
make: *** [build/ch.elf] Error 1
I use ChibiOS 2.4.0 and code sourcery light 2011.03
Any ideas?
Re: C++ global object with destructor link error: __dso_hand
Posted: Sat Feb 25, 2012 10:14 am
by Giovanni
Are you using the arm-none-eabi compiler?
I never hit this problem because static destructors do no make much sense in an embedded system. Anyway try to Google those symbols, there are a lot of hits.
Giovanni
Re: C++ global object with destructor link error: __dso_hand
Posted: Sat Feb 25, 2012 10:55 am
by vitaly
yes, I'm using the arm-none-eabi compiler.
I agree on little sense of static destructor, but anyway...
Re: C++ global object with destructor link error: __dso_hand
Posted: Sat Feb 25, 2012 12:11 pm
by vitaly
After a bit of surfing I see that it's related to dynamic libraries termination. (I don't plan to use embedded dynamic libraries for some time
http://sourcery.mentor.com/public/cxx-abi/abi.html#dso-dtorNow my question boils down to: is it enough to add this line to feel safe?

Code: Select all
extern "C" void *__dso_handle = 0;
Re: C++ global object with destructor link error: __dso_hand
Posted: Sat Feb 25, 2012 12:15 pm
by Giovanni
Probably yes, do you plan to actually execute destructors or just to silence the error?
Giovanni
Re: C++ global object with destructor link error: __dso_hand
Posted: Sat Feb 25, 2012 12:56 pm
by vitaly
I'd like to conceit myself they are executed

Seriously, I have 2 valid imho arguments:
- the same class may have both static and dynamic instances
- it's not uncommon to use destructors to free resources in the spirit of RAII
Anyway, from ChibiOS/RT crt0.c I believe that static destructors are called, aren't they?
Re: C++ global object with destructor link error: __dso_hand
Posted: Sat Feb 25, 2012 2:39 pm
by Giovanni
They are supposed to be called.
Giovanni