[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
[rtl] Follow-Up to Constructors/Destructors
Hi,
I'm new to using RT-Linux but so far I am extremely pleased with the
results I have found.
I was reading through the RTL mailing list and found numerous articles
about C++. Several of
them mentioned calling constructors and destructors for global objects
explicitly. I wanted to add that this is not necessary if you're
using gcc and only slightly modify your code and your makefile.
In init_module() add a call to __do_global_ctors_aux(), and in
cleanup_module() add a call to
__do_global_dtors_aux().
In your makefile incorporate these changes:
CRT_BEG= /the_correct_gcc-lib_path/crtbegin.o
CRT_END= /the_correct_gcc-lib_path/crtend.o
On the link line that specifies all your object files, in front of the
first .o file, add ${CRT_BEG}.
After the last .o file, add ${CRT_END}.
e.g. ld -Ur -static -o module.o ${CRT_BEG} file1.o file2.o file3.o
${CRT_END}
This enables the linker to collect all constructor/destructor and
initialization calls into a list that's kept in the initialization
section. __do_global_ctors_aux() and __do_global_dtors_aux() use this
list.
-Colin Leister
--- [rtl] ---
For more information on Real-Time Linux see:
http://rtlinux.cs.nmt.edu/