g++ for RTLinux --------------- Here you will find a detailed description of how to prepare your system to be able to run C++ programs in RTLinux. Simple C++ code can be easily compiled to generate completely contained code. But more complex language facilities, like exception handling, require special care. This document describes the steps needed to compile and run C++ WITH EXCEPTIONS programs in RTLinux. If your application uses the c++ exception facility then you may (almost for sure) need to recompile the g++ compiler. G++ developers have implemented two different mechanisms to handle exceptions: 1.- Set-jump/long-jump exception handling model: This was the initial mechanism implemented by g++ and although highly portable to any processor, the run time overhead is not negligible. A try-catch block requires always a setup and clean code. 2.- Range table model: Is the current default model used by g++. It is faster because it is not needed to do any setup and cleanup on try-catch blocks. A list of protected regions is created at compile time and then at run time the program counter is used to find the appropriated handler in the list. For more info, please see: http://topaz.cs.byu.edu/cs431/html/text/Ch17.PDF It is required to use the first exception model to run C++ programs. In oder to use the first model IT IS NEEDED to recompile the g++ compiler. That is, it is not possible to generate code that uses the set-jump/long-jump exception handling model by using a compiler flag. The source code of the compiler must by instructed to generate one specific way to handle exceptions. Installation: 1.- Download the source code of the GCC http://gcc.gnu.org/gcc-3.3/ 2.- Extract it in a directory of your choice. 3.- Configure the source code: ./configure --prefix=INSTALLATION_PATH --disable-shared \ --with-gnu-as --with-gnu-ld --disable-threads \ --enable-languages=c,c++ --enable-sjlj-exceptions where INSTALLATION_PATH is the final location of the compiler. For example you can use /opt/gcc 4.- Run: make. And as root run: make install 5.- Now you should have a usable gcc, you can check it by: /opt/gcc/bin/g++ -v check that the --enable-sjlj-exceptions option appear in the output. 6.- Now you can go to the libg++/ directory and run make. This will create a static library with wrapper and runtime support functions needed to run your application as a Linux/RTLinux module. 7.- The last step is to enter into the examples dir. and run them. (The result of compiling an example is an modules with the next syntaxis: _app.o). For instance, to run the example called hello.cc, once the examples have been compiled, you will be have to insert the modules called hello_app.o. NOTE: This is still under development. It has been tested with the new RTLinux-OCERA-2.0 pre release. It should also work with the OCERA-1.0 release, in this case, you need to have dynamic memory allocation support. NOTE2: g++ (c++) for RTLinux needs dynamic memory (that is, a dynamic memory manager), this problem is solving in the OCERA project via the TLSF dynamic memory allocator. In order to avoid this problem in the standard RTLinux installation this package includes the TLSF algorithm (a real-time dynamic memory allocator) as part of the c++ runtime. If you want to use this c++ support to develop strict hard real-time applications, please be careful and take it into account.