CUDA is incompatible with my gcc version

I am having trouble compiling some of the examples that come with the CUDA SDK. I installed the developer driver (version 270.41.19) and the CUDA toolkit, then finally the SDK (version 4.0.17).

Initially, it did not compile at all:

error -- unsupported GNU version! gcc 4.5 and up are not supported! 

I found the line responsible for 81: /usr/local/cuda/include/host_config.h and changed it to:

 //#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4) #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6) 

from that moment I got only a few examples for compilation, it stops:

 In file included from /usr/include/c++/4.6/x86_64-linux-gnu/bits/gthr.h:162:0, from /usr/include/c++/4.6/ext/atomicity.h:34, from /usr/include/c++/4.6/bits/ios_base.h:41, from /usr/include/c++/4.6/ios:43, from /usr/include/c++/4.6/ostream:40, from /usr/include/c++/4.6/iterator:64, from /usr/local/cuda/include/thrust/iterator/iterator_categories.h:38, from /usr/local/cuda/include/thrust/device_ptr.h:26, from /usr/local/cuda/include/thrust/device_malloc_allocator.h:27, from /usr/local/cuda/include/thrust/device_vector.h:26, from lineOfSight.cu:37: /usr/include/c++/4.6/x86_64-linux-gnu/bits/gthr-default.h:251:1: error: pasting "__gthrw_" and "/* Android C library does not provide pthread_cancel, check for `pthread_create' instead. */" does not give a valid preprocessing token make[1]: *** [obj/x86_64/release/lineOfSight.cu.o] Error 1 

As some of the examples compile, I believe this is not a driver issue, but rather should have something to do with an unsupported version of gcc. Downgrading is not an option, since gcc4.6 has the whole system as a dependency at the moment ...

+84
gcc debian cuda
Jul 08 '11 at 9:25 a.m.
source share
17 answers

As already stated, nvcc depends on gcc 4.4. You can configure nvcc to use the correct version of gcc without passing any compiler options by adding soft links to the bin directory created with the nvcc installation.

By default, the cuda binary directory (by default for installation) is / usr / local / cuda / bin, adding softlink to the correct version of gcc from this directory is enough:

sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc

+99
Jan 01 '11 at 13:47
source share
— -

GCC 4.5 and 4.6 are not supported with CUDA - the code will not compile and the rest of the toolbox, including cuda-gdb, will not work properly. You cannot use them, and the restriction is not negotiable.

Your only solution is to install gcc 4.4 as the second compiler (most distributions allow this). There is an option for nvcc --compiler-bindir , which can be used to point to an alternative compiler. Create a local directory, and then make symbolic links to the supported gcc version executables. Transfer this local directory to nvcc using the --compiler-bindir , and you can compile the CUDA code without affecting the rest of your system.




EDIT :

Please note that this question and answer applies to CUDA 4. Since its writing, NVIDIA has continued to expand support for later versions of gcc in the new version of the CUDA toolkit.

  • . Starting with the release of CUDA 4.1, gcc 4.5 is now supported. GCC 4.6 and 4.7 are not supported.
  • Starting with the release of CUDA 5.0, gcc 4.6 is now supported. gcc 4.7 is not supported.
  • Starting with the release of CUDA 6.0, gcc 4.7 is now supported.
  • Starting with the release of CUDA 7.0, gcc 4.8 is fully supported, with 4.9 support in Ubuntu 14.04 and Fedora 21.
  • Starting with the release of CUDA 7.5, gcc 4.8 is fully supported with 4.9 support on Ubuntu 14.04 and Fedora 21.
  • Starting with the release of CUDA 8, gcc 5.3 is fully supported on Ubuntu 16.06 and Fedora 23.
  • Starting with the release of CUDA 9, gcc 6 is fully supported on Ubuntu 16.04, Ubuntu 17.04, and Fedora 25.
  • Gcc 7 support added in CUDA 9.2 release

Currently (as of CUDA 10) there is no gcc 8 support in CUDA.

Note that NVIDIA recently added a very useful table here , which contains the supported compiler and OS matrix for the current version of CUDA.

+49
Jul 08 2018-11-11T00:
source share

For CUDA 10.1:

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

First you need to install gcc and g ++ 8:

 sudo apt install gcc-8 g++-8 



For CUDA 10.0:

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

First you need to install gcc and g ++ 7:

 sudo apt install gcc-7 g++-7 



For CUDA 9:

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

First you need to install gcc and g ++ 6:

 sudo apt install gcc-6 g++-6 



For CUDA 8:

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

First you need to install gcc and g ++ 5:

 sudo apt install gcc-5 g++-5 
+34
Sep 23 '17 at 14:23
source share

Gearoid Murphy's solution works better for me, since on my distribution (Ubuntu 11.10) gcc-4.4 and gcc-4.6 are in the same directory, so -compiler-bindir does not help. The only caveat - I also had to install g ++ - 4.4 and symlink as well:

 sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc sudo ln -s /usr/bin/g++-4.4 /usr/local/cuda/bin/g++ 
+24
Jan 23 '12 at 9:40
source share

For CUDA7.5, these lines work:

 sudo ln -s /usr/bin/gcc-4.9 /usr/local/cuda/bin/gcc sudo ln -s /usr/bin/g++-4.9 /usr/local/cuda/bin/g++ 
+11
Apr 21 '16 at 14:20
source share

Check out how to use “upgrade alternatives” to work around this problem:

... If you install gcc 4.6, you can also use upgrade alternatives to easily switch between versions. This can be configured using:

 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 
+8
Apr 16 '13 at 0:23
source share

In most distributions, you have the option to install another version of gcc and g ++ next to the latest compiler, for example gcc-4.7. In addition, most build systems know the CC and CXX environment variables, which let you specify other C and C ++ compilers, respectively. I suggest something like:

 CC=gcc-4.4 CXX=g++-4.4 cmake path/to/your/CMakeLists.txt 

There must be a similar way for Make files. I do not recommend setting custom symlinks inside / usr / local unless you know what you are doing.

+5
Jan 16 '14 at 12:17
source share

If I use cmake , none of the file editing and linking methods worked, so I compiled using flags that indicate the gcc / g ++ version.
cmake -DCMAKE_C_COMPILER=gcc-6 -DCMAKE_CXX_COMPILER=g++-6..

Worked like a charm.

+4
Jul 20 '18 at 11:00
source share

This works for fedora 23. The gcc compat gcc repositories will be slightly different depending on your version of fedora.

If you install the following repositories:

 sudo yum install compat-gcc-34-c++-3.4.6-37.fc23.x86_64 compat-gcc-34-3.4.6-37.fc23.x86_64 

Now make soft links as above if your cuda bin folder is in /usr/local/cuda/

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

Now you can compile with nvcc without gcc version error.

+3
Dec 04 '15 at 22:26
source share

Gearoid Murphy's solution works like a charm. For me, I had two directories for cuda -

 /usr/local/cuda /usr/local/cuda-5.0 

Instant links should only be added to the directory listed below -

 /usr/local/cuda 

In addition, both g ++ and gcc links were needed, as SchighSchagh mentioned.

+2
Feb 13 '13 at 7:44
source share

Another way to configure nvcc to use a specific version of gcc (e.g. gcc-4.4) is to edit the nvcc.profile file and change the PATH to include the path to gcc that you want to use first.

For example (gcc-4.4.6 installed in / opt):

 PATH += /opt/gcc-4.4.6/lib/gcc/x86_64-unknown-linux-gnu/4.4.6:/opt/gcc-4.4.6/bin:$(TOP)/open64/bin:$(TOP)/share/cuda/nvvm:$(_HERE_): 

The location of the nvcc.profile file is changing, but it must be in the same directory as the nvcc executable itself.

This is a bit hacked as nvcc.profile is not intended to set up the user according to the nvcc manual, but it was the solution that helped me the best.

+2
Mar 31 '13 at 3:59
source share

CUDA after some header modifications compatible with gcc4.7 and possibly a higher version: https://www.udacity.com/wiki/cs344/troubleshoot_gcc47

+2
May 23 '13 at 13:35
source share

For people like me who are confused when using cmake , the FindCUDA.cmake script overrides some things from nvcc.profile . You can specify the nvcc host compiler by setting CUDA_HOST_COMPILER according to http://public.kitware.com/Bug/view.php?id=13674 .

+2
Jul 29 '13 at 0:30
source share

I had to install older versions of gcc, g ++.

  sudo apt-get install gcc-4.4 sudo apt-get install g++-4.4 

Make sure gcc-4.4 is in / usr / bin /, as well as for g ++ Then I could use the solution above:

  sudo ln -s /usr/bin/gcc-4.4 /opt/cuda/bin/gcc sudo ln -s /usr/bin/g++-4.4 /opt/cuda/bin/g++ 
+2
Nov 18 '14 at 16:52
source share

In $CUDA_HOME/include/host_config.h find these lines (they may vary slightly depending on the version of CUDA):

 //... #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9) #error -- unsupported GNU version! gcc versions later than 4.9 are not supported! #endif [> __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 9) <] //... 

Delete or modify them to suit your condition.

Please note that this method is potentially dangerous and may break your assembly. For example, gcc 5 uses C ++ 11 by default, however this does not apply to nvcc with CUDA 7.5. The workaround is to add

--Xcompiler="--std=c++98" for CUDA <= 6.5

or

--std=c++11 for CUDA> = 7.0.

0
Sep 13 '16 at 20:29
source share

To compile CUDA 8.0 examples on Ubuntu 16.10, I did:

 sudo apt-get install gcc-5 g++-5 cd /path/to/NVIDIA_CUDA-8.0_Samples # Find the path to the library (this should be in NVIDIA Makefiles) LIBLOC=`find /usr/lib -name "libnvcuvid.so.*" | head -n1 | perl -pe 's[/usr/lib/(nvidia-\d+)/.*][$1]'` # Substitute that path into the makefiles for the hard-coded, incorrect one find . -name "*.mk" | xargs perl -pi -e "s/nvidia-\d+/$LIBLOC/g" # Make using the supported compiler HOST_COMPILER=g++-5 make 

This has the advantage that you do not modify the entire system or create symbolic links for binary files only (which can cause problems with linking libraries).

0
Mar 26 '17 at 13:04 on
source share

This solved my problem:

 sudo rm /usr/local/cuda/bin/gcc sudo rm /usr/local/cuda/bin/g++ sudo apt install gcc-4.4 g++-4.4 sudo ln -s /usr/bin/gcc-4.4 /usr/local/cuda/bin/gcc sudo ln -s /usr/bin/g++-4.4 /usr/local/cuda/bin/g++ 
0
Feb 14 '19 at 6:13
source share



All Articles