Linux C++ Compilers

From MobileRobots Research and Academic Customer Support

Jump to: navigation, search

On GNU/Linux, you should use G++ (The GNU GCC C++ compiler). There are two incompatible versions of GCC: GCC 3.4 and GCC 4.

GCC version 3.4 was used to build Debian 3.1 packages and generic TGZ packages that are either marked with "gcc34" in the package file name, or which are not marked with a GCC version. GCC 3.4 was also used to build the RPM packages for RedHat 7. You must use 3.4 when building programs that link to libraries from these packages.

GCC version 4 was used to build packages for Debian 5 or TGZ or other packages marked with "gcc4" in the package file name. You must use 4.x or later when building programs that link to libraries from these packages.

For packages with source code provided (such as ARIA), you can recompile them by entering the package's directory (e.g. /usr/local/Aria for ARIA) and running make clean; make all (for ArNetworking, then cd ArNetworking and make clean; make all, and similarly for all other auxiliary libraries you have.)

Source code is not available for ARNL, SONARNL, MOGS and some other optional libraries however, so it cannot be recompiled, instead install the appropriate package for your Debian version and compiler version.

You can check the version number of G++ by running g++ --version

On Debian, you can have multiple versions of GCC installed with different names, and you can select which one is the default version used for the g++ command, see below for instructions.

More information and documentation about GCC is available at http://gcc.gnu.org, and in the gcc 'man' page. More information about Make is at http://www.gnu.org/software/make/. Several graphical IDE applications are available for use with GCC, though none are directly supported by MobileRobots (i.e. we won't be able to help you with IDE-specific issues).

(TODO: Split this into 5 pages)

Contents

I have upgraded my operating system or my compiler, or moved ARIA and other code to a different system with a different compiler, and now I get bad data, link errors, or mysterious crashes. What's wrong?

The ARIA, ARNL, and other library Linux packages install share libraries built with GCC 3.4 (unless otherwise indicated). If your different OS has different GCC or C library versions, then two things might happen:

1. Programs might end up linked against different versions of the same libary. If, for example, libAria.so was built with gcc 3.4 and linked against libstdc++.so.6, and your other system uses gcc 3.3 and libstdc++.so.5, running the 'ldd' command on a program with mixed linkage will show both libstdc++.so.6 and libstdc++.so.5 linked as shared libraries. Sometimes this works without problems, sometimes not. The solutions are to either install GCC 3.4, or to recompile ARIA using the new version. Note, however, that you must use GCC 3.4 if you are using ARNL.

2. If you build a program with a version of GCC that produces code that isn't binary-compatbile with a library, it will fail to link, with an error message about incompatible library versions or "personality" symbols. For example GCC 3.4 is not ABI-compatible with GCC 2.95 or with GCC 4.x. libAria.so, libArNetworking, libArnl.so, etc. normally have been built with GCC 3.4. If you build a program with GCC 2.95, then try to link against that libAria.so, the linker will fail. The solutions are to either use the same GCC version (3.4), or to recompile libAria.so and all other libraries using your preferred GCC version.

Similarly, on Windows, your program and the ARIA DLL must be built with compatible compilers. In particular, each version of Visual C++ is generally not compatible with other versions, so you must recompile ARIA if using a compiler other than VC .NET/2003.

How do I determine which version of GCC I have?

Run 'g++ --version' to see the version number of the GCC C++ compiler.

How can I specify a different version or variant of g++ when building stuff in ARIA?

All of the Makefiles included with ARIA and ARIA extra libraries honor the 'CXX' environment variable. By default, "g++" is used as the compiler command, but if you set 'CXX', then that compiler command is used instead. So if you want to use "g++-3.4" as the compiler command instead of "g++", set CXX to "g++-3.4", for example:

export CXX="g++-3.4"
make examples/demo

My Debian system has multiple versions of GCC installed; how do I select which one to use?

Some versions of Debian have several GCC versions installed, for example GCC 3.4 and GCC 4.1, or GCC 3.3 and GCC 3.4. These will be named for their versions, for example, the C++ compiler for GCC 3.4 is called g++-3.4 and for GCC 4.1 it is called g++-4.1, etc.. Some systems may have other versions as well.

One of these versions is configured to be the default g++ command. When installed by MobileRobots, most Debian systems on robot on-board computers are configured to use GCC 3.4 as the default. Your own computers with Debian installed (and some MobileRobots installed systems) may have other versions set as the default (such as 3.3 or 4.x).

To use a different version temporarily for building ARIA libraries and examples, you may set an environment variable 'CXX' to an alternative compiler command; ARIA's Makefiles use the value of this environment variable as the C++ compiler command if it is set.

But to permanently change the system default 'g++' command for all users and to persist after rebooting, use the 'galternatives' GUI program, or the 'update-alternatives' command as root. For example, to choose GCC 3.4:

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-3.4 50 --slave /usr/bin/g++ g++ /usr/bin/g++-3.4 
update-alternatives --set gcc /usr/bin/gcc-3.4

Then, in the future, use

update-alternatives --config gcc

to select a different gcc and g++ version.

Or using galternatives, change the entries for c++ and cc to use g++-3.4 and gcc-3.4.

GCC 3.4 is configured as the default alternative on most Debian systems installed by MobileRobots on onboard computers, and is the version used to build the development libraries.

My RedHat system seems to only have GCC 2.95. Where is 3.4?

Robot on-board computers shipped with RedHat 7.3 have been specially customized with G++ 3.4.1 installed in /usr/local/gcc-3.4.1. The 'guest' user's PATH and LD_LIBRARY_PATH environment variables are configured to include this directory. New users added to the system can be similarly configured. GCC 3.4 can also be installed on any other computer using your operating system's normal package installation tools or by downloading it from http://gcc.gnu.org and manually installing it as we have done for RedHat 7.3 computers (ARIA includes quick instructions for compiling and installing GCC).

Personal tools