Using C++ with VxWorks Using the GNU g++ compiler to develop C++ code for VxWorks is really quite simple. The most difficult part is building the compiler and support tools. Once this is done developing C++ code for VxWorks is a snap. The following is how we use g++ tools on our Suns for 68k targets. Please note that this has been tested only on the following systems: Solaris 2.3/2.4 and tested only on the following targets: Tadpole TP41V, Motorola MVME-167 & MVME-133A running VxWorks 5.2. The big change: --------------- Previous versions of libg++ where made such that all needed items were in libg++.a. Starting with version 2.7.0 the functions that are part of the C++ standard library are in libstdc++. You will have to add/change link lines! Building the cross development tools: ------------------------------------- Obtain gcc-2.7.x. (Note: we are currently running gcc-2.7.0 & libg++-2.7.0) First, untar everything. Move into the gcc directory. Now, the first thing to do is to build gcc for your host. Follow the installation instructions. Make sure to read the INSTALL file, particularly the sections on building cross compilers. Run configure using --target=m68k-wrs-vxworks (or whatever). This way you can have your other crosstools named consistently with gcc. We found that the following changes to the generated makefile are useful: 1> Change CFLAGS to -O2 & BOOT_CFLAGS to $(CFLAGS). 2> Change GCC_FOR_TARGET to ./xgcc -B./ -I/vx/h. 3> Remove -g1 from LIBGCC2_CFLAGS. 4> Add -I/vx/h -DVXWORKS to the GCC_FOR_TARGET definition for compiling libobjc.a. Run make and install. Building libg++/stdc++ for VxWorks: -------------------------------------- 1> Obtain libg++ and unpack it. 2> Move into the directory libg++-2.x.x. 3> Get the patch file libg++-2.7.x. 4> Run configure: "./configure --host=your_host_type --target=m68k-wrs-vxworks". 4> Apply the patch file. You may have to apply the base level Makefile patches by hand. 5> Run make. VxWorks and g++: ---------------- To call a routine compiled under g++ you must turn off name mangling for that routine: extern "C" { void myRoutine(int); }; To use any globally declared objects (including cin, cout, cerr), you can do the following: 1> Before you access any of the global objects, call __do_global_ctors(): extern "C" { void __do_global_ctors(); .... void mystart() { __do_global_ctors(); .... 2> Link your object files using the -Ur option of the GNU linker: 'whatever_you_called_it' -Ur -X -o xx.o yy.o ... \ -L/zzz -lg++ -libstdc++ -libgcc All in all quite simple. The VxWorks archive has several C++ classes already. Some files of interest are: flags_class.shar msgque_class.shar pipe.shar task_class.shar wdog_class Richard Neitzel thor@atd.ucar.edu Torren med sitt skjegg National Center For Atmospheric Research lokkar borni under sole-vegg Box 3000 Boulder, CO 80307-3000 Gjø'i med sitt shinn 303-497-2057 jagar borni inn.