Office of Information Technology
Home

Calendar

Map
Home
Computing

Library

Search
Transitioning to gcc 3.2

Transitioning to gcc 3.2

Here is a short FAQ about using the new GCC compiler here at umbc.

Table of Contents

  1. Why gcc-3.2?
  2. Important note about C++ libraries.
  3. A correct HelloWorld.cpp example.
  4. Using the old version of gcc when all else fails

Why gcc-3.2?

OIT has released a new version of the GCC compiler suite on all of central UNIX login machines and Linux lab images. This new version, GCC 3.2, fixes a lot of bugs present in the old version and contains a completely revamped C++ subsystem that may cause C++ programs that had previously compiled to fail under this new version in some circumstances. This FAQ is meant to help address most of these issues.

Important note about C++ libraries.

The new version of GCC has changed its ABI(Application Binary Interface) for any C++ generated code. This means that any C++ object files, programs, and shared libraries which were compiled with different versions of the compiler will no longer work together. For instance, if you have a shared lib, libfoo.so, which was built with gcc v2.95 and is used by a program, bar, which is then built with gcc v3.2, it will no longer be able to link against libfoo (and vice versa with the compiler versions). Both libfoo and bar must be compiled with the same version to correctly function.

THIS DOES NOT AFFECT C CODE, ONLY C++. Libraries and programs written in C will continue to function regardless of the mix of compiler versions.


A correct HelloWorld.cpp example.

One the most notable differences in the new version of GCC is that it strictly(ie: correctly) enforces the use of namespaces in C++. Therefore symbols like 'cout' are undefined outside of the scope of the std namespace. Below is a standards compliant implementation of the classic Hello World program in C++:

#include <iostream> //notice no .h suffix

using namespace std; //required for resolving the 'cout' symbol

int main(int argc, char *argv[]) 
{
  cout << "Hello World" << endl;
  return(0);
}

Using the old version of gcc when all else fails

If you are unable to fix your code to meet the c++ specification, you can still compile it with the old version of gcc. To do this, simply change your makefile(or whatever build environment you're using) to call gcc-2.95 or g++-2.95 and it will be compiled as before.
Office of Information Technology • Main Office: ECS 125 • Phone: 410-455-3838 • Email: oit@umbc.edu