cs344 »

Use GCC 4.6.x Instead of Forcing 4.7 to (Sorta) Work

The steps given below, and originating from an Arch Linux bug report involve disabling atomic operations (#undef _GLIBCXX_ATOMIC_BUILTINS). If you go through them and try some simple samples, everything will seem fine, but our course uses these atomic operations.

The simpler solution is simply to build CUDA programs using 4.6, which for Ubuntu 12.10 is available as a package. There are some notes on doing this on this page about setting up for OpenGL + CUDA on an Optimus laptop running Ubuntu 12.10

If you install gcc 4.6 you can also use the update-alternatives command to allow for easily switching between versions. This can be configured with:

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7 
sudo update-alternatives --config gcc

Incompatibility with GCC 4.7


If you install on Ubuntu 12.10 (and to not also install gcc 4.6 as above) you may get these error messages during installation:

Toolkit:  Installation Failed. Using unsupported Compiler.
Samples:  Installation Failed. Missing required libraries.

The flag " -override compiler" can be used to suppress the error messages and allow installation to complete:

/cuda_5.0.35_linux_64_ubuntu11.10-1.run  -override compiler


Compiling with GCC 4.7 produces errors like this:

error: identifier "__atomic_fetch_add" is undefined

Here is a workaround (tested on Arch Linux).

Add a new header file to the project, say gcc_cuda_compat.h and add these two lines:

#undef _GLIBCXX_USE_INT128

And finally add this to the NVCC_OPTS in your Makefile:

--pre-include gcc_cuda_compat.h

So it looks something like this:

NVCC_OPTS=-O3 -arch=sm_20 -Xcompiler -Wall -Xcompiler -Wextra -m64 --pre-include gcc_cuda_compat.h

This should let you compile with GCC 4.7.

Bug Report

Addendum for CUDA 5.0 Installed with cuda_5.0.35_linux_64_ubuntu11.10-1.run

This release does an explicit check of the compiler version and refuses to compile on anything over 4.6. To fix that edit this file:


Edit line 82 to stop the compiler refusing to run:

// #error — unsupported GNU version! gcc 4.7 and up are not supported!
#warning — unsupported GNU version! gcc 4.7 and up are not supported! (was an error --- [AHC])