Wrong GCC version For CUDA (Linux) -- How to solve

While using a Blender I built on Linux (Kubuntu 19.04 Eoan Ermine), I ran into a strange problem when I tried to do a GPU CUDA render: the render failed and the console told me I had the wrong version of gcc installed. This strange bug only occurs after Blender is built.

I want to share the solution I found for the problem:
First, make sure you have the right version of gcc and g++ installed:
sudo apt install gcc-8 g++-8
then follow the instructions here: Ubuntu 16.04: `unsupported GNU version! gcc versions later than 4.9 are not supported!` · Issue #246 · NervanaSystems/neon · GitHub
(He’s using an even older version of gcc and cuda, make sure to change the numbers like I did here)

sudo ln -s /usr/bin/gcc-8 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-8 /usr/local/cuda/bin/g++

What does this do? This creates a symbolic link in cuda’s binary directory that tells it to use gcc-8 instead of gcc and g++-8 instead of g++. cuda searches its bin for “gcc” and “g++”, but the files are actually linked to “gcc-8” and “g++-8” instead. No need to change cuda’s config files.

I don’t know if this will work for everyone that runs into this issue, but it was easy and worked for me.

I hope this helps someone :smiley:

On a related note-- should there be a compiler warning or something? Is it normal to need to have cuda installed to the system to compile the render kernels? I would like to understand more why I had this problem.

2 Likes

CUDA kernels are usually compiled along with the Blender build as explained here:
https://wiki.blender.org/wiki/Building_Blender/CUDA

Or they can be compiled at runtime if the CUDA toolkit is installed, which is mainly meant for development.

The CUDA toolkit can be picky about the GCC version. At some point we might switch to enabling WITH_CYCLES_CUBIN_COMPILER by default which would avoid the problem.

1 Like

I have also tried using the update-alternatives (see https://askubuntu.com/questions/26498/how-to-choose-the-default-gcc-and-g-version) method for building another project, and had a build fail for Mantaflow’s code because of the g++ version (it seems). So, this first method appears to be the better choice, since one may have to manually choose gcc/g++ version if update-alternatives is used to maintain the options. Still, it seems like it is necesary for compiling some projects. I had a go at compiling an AI project that used CUDA and the first trick, placing symbolic links in CUDA’s bin, didn’t work.

I want to mention it here to warn folks that they might accidentally create build problems if they mess with their gcc/g++ settings too much! But it’s easy to fix.