In my case, I did not have root privileges, so I could not completely replace the current version of gcc (4.7) with an older version 4.4 (which, I think, would be a bad alternative). Although I had rights where CUDA was installed. My solution was to create an additional folder (e.g. / somepath / gccfornvcc /), wherever I was right, and then create a link to an approved nvcc compiler. I already have gcc 4.4 (but you can install it without uninstalling the current version).
ln -s [path to gcc 4.4]/gcc-4.4 /somepath/gccfornvcc/gcc
Then in the same folder where the nvcc binary lives, you should find a file called nvcc.profile. You just need to add the following line:
compiler-bindir = /somepath/gccfornvcc
And that will make nvcc use the correct compiler. This helps keep the system in good condition by keeping the latest compiler, but nvcc (only nvcc) will use the old version of the compiler.
source share