CUDA与我的gcc版本不兼容。

时间:2021-11-07 19:37:15

I have troubles compiling some of the examples shipped with CUDA SDK. I have installed the developers driver (version 270.41.19) and the CUDA toolkit, then finally the SDK (both the 4.0.17 version).

我有麻烦编译一些附带CUDA SDK的示例。我已经安装了开发人员驱动程序(版本270.41.19)和CUDA工具包,最后是SDK(4.0.17版本)。

Initially it didn't compile at all giving:

最初它根本没有编译:

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

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

我发现这一行代码是81:/usr/local/cuda/include/host_config。h并将其改为:

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

from that point on I got only a few of the examples to compile, it stops with:

从那时起,我只得到了几个编译示例,它停止了:

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's 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 reckon this is not a driver problem, but rather must have something to do with an unsupported gcc version. Downgrading is not an option as gcc4.6 has a whole system as a dependency at this point...

作为示例编译的一部分,我认为这不是驱动程序问题,而是与不支持的gcc版本有关。降级不是一个选项,因为gcc4.6在这一点上有一个完整的系统。

15 个解决方案

#1


86  

As already pointed out, nvcc depends on gcc 4.4. It is possible to configure nvcc to use the correct version of gcc without passing any compiler parameters by adding softlinks to the bin directory created with the nvcc install.

正如已经指出的,nvcc依赖于gcc 4.4。可以将nvcc配置为使用gcc的正确版本,而不需要通过添加与nvcc安装创建的bin目录的软链接来传递任何编译器参数。

The default cuda binary directory (the installation default) is /usr/local/cuda/bin, adding a softlink to the correct version of gcc from this directory is sufficient:

默认的cuda二进制目录(安装默认值)是/usr/local/cuda/bin,在此目录中添加一个到正确版本的gcc的软链接就足够了:

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

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

#2


38  

gcc 4.5 and 4.6 are not supported with CUDA - code won't compile and the rest of the toolchain, including cuda-gdb, won't work properly. You cannot use them, and the restriction is non-negotiable.

gcc 4.5和4.6不支持CUDA -代码不会编译,其余的工具链,包括CUDA -gdb,都不能正常工作。你不能使用它们,而且这个限制是不可协商的。

Your only solution is to install a gcc 4.4 version as a second compiler (most distributions will allow that). There is an option to 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. Pass that local directory to nvcc via the --compiler-bindir option, and you should be able to compile CUDA code without affecting the rest of your system.

您唯一的解决方案是安装gcc 4.4版本作为第二个编译器(大多数发行版都允许这样做)。可以选择nvcc——编译器-bindir,它可以用来指向另一个编译器。创建一个本地目录,然后对支持的gcc版本可执行文件进行符号链接。通过-编译-bindir选项将本地目录传递给nvcc,您应该能够编译CUDA代码,而不会影响系统的其他部分。


EDIT:

编辑:

Note that this question, and answer, pertain to CUDA 4. Since it was written, NVIDIA has continued to expand support for later gcc versions in newer CUDA toolchain release

请注意这个问题和答案,属于CUDA 4。自从它被编写以来,NVIDIA继续扩展对后来的CUDA工具链版本的gcc版本的支持。

  • As of the CUDA 4.1 release, gcc 4.5 is now supported. gcc 4.6 and 4.7 are unsupported.
  • 在CUDA 4.1版本中,现在支持gcc 4.5。gcc 4.6和4.7不受支持。
  • As of the CUDA 5.0 release, gcc 4.6 is now supported. gcc 4.7 is unsupported.
  • 在CUDA 5.0版本中,现在支持gcc 4.6。gcc 4.7是不支持的。
  • As of the CUDA 6.0 release, gcc 4.7 is now supported.
  • 在CUDA 6.0版本中,现在支持gcc 4.7。
  • As of the CUDA 7.0 release, gcc 4.8 is fully supported, with 4.9 support on Ubuntu 14.04 and Fedora 21.
  • 在CUDA 7.0版本中,gcc 4.8得到了完全支持,在Ubuntu 14.04和Fedora 21上有4.9个支持。
  • As of the CUDA 7.5 release, gcc 4.8 is fully supported, with 4.9 support on Ubuntu 14.04 and Fedora 21.
  • 在CUDA 7.5版本中,gcc 4.8得到了完全支持,在Ubuntu 14.04和Fedora 21上有4.9个支持。
  • As of the CUDA 8 release, gcc 5.3 is fully supported on Ubuntu 16.06 and Fedora 23.
  • 在CUDA 8版本中,gcc 5.3在Ubuntu 16.06和Fedora 23上得到了完全支持。
  • As of the CUDA 9 release, gcc 6 is fully supported on Ubuntu 16.04, Ubuntu 17.04 and Fedora 25.
  • 在CUDA 9版本中,gcc 6在Ubuntu 16.04、Ubuntu 17.04和Fedora 25上得到了完全支持。

There is presently (as of CUDA 9) no gcc 7 support in CUDA.

目前(CUDA 9)在CUDA没有gcc 7的支持。

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

注意,NVIDIA最近在这里添加了一个非常有用的表,其中包含当前CUDA版本支持的编译器和操作系统矩阵。

#3


23  

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

从我的发行版(Ubuntu 11.10)、gcc-4.4和gcc-4.6都在同一个目录中,Gearoid Murphy的解决方案对我来说更好了,所以,编译器-bindir没有帮助。唯一需要注意的是,我还必须安装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++

#4


12  

Update:

更新:

For CUDA 9:

对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++

You need to have gcc and g++ 6 installed first:

您需要先安装gcc和g++ 6:

sudo apt install gcc-6 g++-6

Old answer:

旧的回答:

For CUDA 8:

对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++

You need to have gcc and g++ 5 installed first:

您需要先安装gcc和g++ 5:

sudo apt install gcc-5 g++-5

#5


10  

For CUDA7.5 these lines work:

对于CUDA7.5,这些线条是:

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++

#6


6  

Check out how to use "update-alternatives" to get around this issue:

查看如何使用“更新替代”来解决这个问题:

... 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:

…如果您安装了gcc 4.6,您也可以使用update- options命令来方便地在版本之间切换。这可以配置为:

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

#7


3  

On most distributions you have the possibility to install another gcc and g++ version beside a most recent compiler like gcc-4.7. In addition most build systems are aware of the CC and CXX environment variables, which let specify you other C and C++ compilers respectively. SO I suggest something like:

在大多数发行版中,您都有可能在gcc-4.7这样的最新编译器旁边安装另一个gcc和g++版本。此外,大多数构建系统都知道CC和CXX环境变量,它们分别指定了其他C和c++编译器。所以我建议:

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

For Makefiles there should be a similar way. I do not recommend setting custom symlinks within /usr/local unless you know what you are doing.

对于makefile,应该有类似的方法。我不建议在/usr/local中设置自定义符号链接,除非您知道自己在做什么。

#8


2  

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

Gearoid Murphy的解决方案很有魅力。我有两个cuda的目录。

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

The soft links had to be added only to the directory mentioned below -

软链接只能添加到下面提到的目录中。

/usr/local/cuda 

Also, both g++ and gcc soft links were required as mentioned by SchighSchagh.

同时,g++和gcc软链接都是SchighSchagh提到的。

#9


2  

Another way of configuring nvcc to use a specific version of gcc (gcc-4.4, for instance), is to edit nvcc.profile and alter PATH to include the path to the gcc you want to use first.

另一种配置nvcc来使用特定版本的gcc(例如gcc-4.4)的方法是编辑nvcc。配置文件和修改路径,以包含您想要首先使用的gcc的路径。

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

例如(gcc-4.4.6安装在/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 nvcc.profile varies, but it should be in the same directory as the nvcc executable itself.

学校网站的位置。配置文件不同,但它应该与nvcc可执行文件本身相同。

This is a bit of a hack, as nvcc.profile is not intended for user configuration as per the nvcc manual, but it was the solution which worked best for me.

这有点像nvcc。配置文件不是按照nvcc手册为用户配置的,但它是最适合我的解决方案。

#10


2  

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

CUDA在一些头修改后与gcc4.7兼容,可能更高版本:https://www.udacity.com/wiki/cs344/troubleshoot_gcc47。

#11


2  

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

我必须安装旧版本的gcc, g++。

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

Check that gcc-4.4 is in /usr/bin/, and same for g++ Then I could use the solution above:

检查gcc-4.4在/usr/bin/中,对于g++,我可以使用上面的解决方案:

    sudo ln -s /usr/bin/gcc-4.4 /opt/cuda/bin/gcc
    sudo ln -s /usr/bin/g++-4.4 /opt/cuda/bin/g++

#12


2  

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

这适用于fedora 23。根据您的fedora版本,compat gcc存储库将略有不同。

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 the soft links as mentioned above assuming your cuda bin folder is in /usr/local/cuda/

现在,假设您的cuda bin文件夹在/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++

You should now be able to compile with nvcc without the gcc version error.

现在,您应该能够在没有gcc版本错误的情况下使用nvcc进行编译。

#13


1  

For people like me who get confused while using cmake, the FindCUDA.cmake script overrides some of the stuff from nvcc.profile. You can specify the nvcc host compiler by setting CUDA_HOST_COMPILER as per http://public.kitware.com/Bug/view.php?id=13674.

对于像我这样在使用cmake时感到困惑的人,FindCUDA。cmake脚本覆盖了来自nvcc.profile的一些内容。您可以通过将CUDA_HOST_COMPILER设置为http://public.kitware.com/Bug/view.php?id=13674来指定nvcc主机编译器。

#14


0  

In $CUDA_HOME/include/host_config.h, find lines like these (may slightly vary between different CUDA version):

在CUDA_HOME / include / host_config美元。h,找到像这样的线(在不同的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) <]
//...

Remove or change them matching your condition.

删除或更改它们与您的条件相匹配。

Note this method is potentially unsafe and may break your build. For example, gcc 5 uses C++11 as default, however this is not the case for nvcc as of CUDA 7.5. A workaround is to add

注意,此方法可能不安全,可能会破坏您的构建。例如,gcc 5使用c++ 11作为默认值,但是对于nvcc来说,这不是CUDA 7.5的情况。一个变通方法就是添加。

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

——Xcompiler =“- std = c + + 98”CUDA < = 6.5

or

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

- std = c + + 11 CUDA > = 7.0。

#15


0  

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

为了在Ubuntu 16.10上编译CUDA 8.0示例,我做到了:

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's 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 of not modifying the whole system or making symlinks to just the binaries (that could cause library linking problems.)

这样做的好处是不会修改整个系统,或者只将符号链接到二进制文件(这会导致库链接问题)。

#1


86  

As already pointed out, nvcc depends on gcc 4.4. It is possible to configure nvcc to use the correct version of gcc without passing any compiler parameters by adding softlinks to the bin directory created with the nvcc install.

正如已经指出的,nvcc依赖于gcc 4.4。可以将nvcc配置为使用gcc的正确版本,而不需要通过添加与nvcc安装创建的bin目录的软链接来传递任何编译器参数。

The default cuda binary directory (the installation default) is /usr/local/cuda/bin, adding a softlink to the correct version of gcc from this directory is sufficient:

默认的cuda二进制目录(安装默认值)是/usr/local/cuda/bin,在此目录中添加一个到正确版本的gcc的软链接就足够了:

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

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

#2


38  

gcc 4.5 and 4.6 are not supported with CUDA - code won't compile and the rest of the toolchain, including cuda-gdb, won't work properly. You cannot use them, and the restriction is non-negotiable.

gcc 4.5和4.6不支持CUDA -代码不会编译,其余的工具链,包括CUDA -gdb,都不能正常工作。你不能使用它们,而且这个限制是不可协商的。

Your only solution is to install a gcc 4.4 version as a second compiler (most distributions will allow that). There is an option to 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. Pass that local directory to nvcc via the --compiler-bindir option, and you should be able to compile CUDA code without affecting the rest of your system.

您唯一的解决方案是安装gcc 4.4版本作为第二个编译器(大多数发行版都允许这样做)。可以选择nvcc——编译器-bindir,它可以用来指向另一个编译器。创建一个本地目录,然后对支持的gcc版本可执行文件进行符号链接。通过-编译-bindir选项将本地目录传递给nvcc,您应该能够编译CUDA代码,而不会影响系统的其他部分。


EDIT:

编辑:

Note that this question, and answer, pertain to CUDA 4. Since it was written, NVIDIA has continued to expand support for later gcc versions in newer CUDA toolchain release

请注意这个问题和答案,属于CUDA 4。自从它被编写以来,NVIDIA继续扩展对后来的CUDA工具链版本的gcc版本的支持。

  • As of the CUDA 4.1 release, gcc 4.5 is now supported. gcc 4.6 and 4.7 are unsupported.
  • 在CUDA 4.1版本中,现在支持gcc 4.5。gcc 4.6和4.7不受支持。
  • As of the CUDA 5.0 release, gcc 4.6 is now supported. gcc 4.7 is unsupported.
  • 在CUDA 5.0版本中,现在支持gcc 4.6。gcc 4.7是不支持的。
  • As of the CUDA 6.0 release, gcc 4.7 is now supported.
  • 在CUDA 6.0版本中,现在支持gcc 4.7。
  • As of the CUDA 7.0 release, gcc 4.8 is fully supported, with 4.9 support on Ubuntu 14.04 and Fedora 21.
  • 在CUDA 7.0版本中,gcc 4.8得到了完全支持,在Ubuntu 14.04和Fedora 21上有4.9个支持。
  • As of the CUDA 7.5 release, gcc 4.8 is fully supported, with 4.9 support on Ubuntu 14.04 and Fedora 21.
  • 在CUDA 7.5版本中,gcc 4.8得到了完全支持,在Ubuntu 14.04和Fedora 21上有4.9个支持。
  • As of the CUDA 8 release, gcc 5.3 is fully supported on Ubuntu 16.06 and Fedora 23.
  • 在CUDA 8版本中,gcc 5.3在Ubuntu 16.06和Fedora 23上得到了完全支持。
  • As of the CUDA 9 release, gcc 6 is fully supported on Ubuntu 16.04, Ubuntu 17.04 and Fedora 25.
  • 在CUDA 9版本中,gcc 6在Ubuntu 16.04、Ubuntu 17.04和Fedora 25上得到了完全支持。

There is presently (as of CUDA 9) no gcc 7 support in CUDA.

目前(CUDA 9)在CUDA没有gcc 7的支持。

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

注意,NVIDIA最近在这里添加了一个非常有用的表,其中包含当前CUDA版本支持的编译器和操作系统矩阵。

#3


23  

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

从我的发行版(Ubuntu 11.10)、gcc-4.4和gcc-4.6都在同一个目录中,Gearoid Murphy的解决方案对我来说更好了,所以,编译器-bindir没有帮助。唯一需要注意的是,我还必须安装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++

#4


12  

Update:

更新:

For CUDA 9:

对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++

You need to have gcc and g++ 6 installed first:

您需要先安装gcc和g++ 6:

sudo apt install gcc-6 g++-6

Old answer:

旧的回答:

For CUDA 8:

对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++

You need to have gcc and g++ 5 installed first:

您需要先安装gcc和g++ 5:

sudo apt install gcc-5 g++-5

#5


10  

For CUDA7.5 these lines work:

对于CUDA7.5,这些线条是:

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++

#6


6  

Check out how to use "update-alternatives" to get around this issue:

查看如何使用“更新替代”来解决这个问题:

... 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:

…如果您安装了gcc 4.6,您也可以使用update- options命令来方便地在版本之间切换。这可以配置为:

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

#7


3  

On most distributions you have the possibility to install another gcc and g++ version beside a most recent compiler like gcc-4.7. In addition most build systems are aware of the CC and CXX environment variables, which let specify you other C and C++ compilers respectively. SO I suggest something like:

在大多数发行版中,您都有可能在gcc-4.7这样的最新编译器旁边安装另一个gcc和g++版本。此外,大多数构建系统都知道CC和CXX环境变量,它们分别指定了其他C和c++编译器。所以我建议:

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

For Makefiles there should be a similar way. I do not recommend setting custom symlinks within /usr/local unless you know what you are doing.

对于makefile,应该有类似的方法。我不建议在/usr/local中设置自定义符号链接,除非您知道自己在做什么。

#8


2  

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

Gearoid Murphy的解决方案很有魅力。我有两个cuda的目录。

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

The soft links had to be added only to the directory mentioned below -

软链接只能添加到下面提到的目录中。

/usr/local/cuda 

Also, both g++ and gcc soft links were required as mentioned by SchighSchagh.

同时,g++和gcc软链接都是SchighSchagh提到的。

#9


2  

Another way of configuring nvcc to use a specific version of gcc (gcc-4.4, for instance), is to edit nvcc.profile and alter PATH to include the path to the gcc you want to use first.

另一种配置nvcc来使用特定版本的gcc(例如gcc-4.4)的方法是编辑nvcc。配置文件和修改路径,以包含您想要首先使用的gcc的路径。

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

例如(gcc-4.4.6安装在/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 nvcc.profile varies, but it should be in the same directory as the nvcc executable itself.

学校网站的位置。配置文件不同,但它应该与nvcc可执行文件本身相同。

This is a bit of a hack, as nvcc.profile is not intended for user configuration as per the nvcc manual, but it was the solution which worked best for me.

这有点像nvcc。配置文件不是按照nvcc手册为用户配置的,但它是最适合我的解决方案。

#10


2  

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

CUDA在一些头修改后与gcc4.7兼容,可能更高版本:https://www.udacity.com/wiki/cs344/troubleshoot_gcc47。

#11


2  

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

我必须安装旧版本的gcc, g++。

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

Check that gcc-4.4 is in /usr/bin/, and same for g++ Then I could use the solution above:

检查gcc-4.4在/usr/bin/中,对于g++,我可以使用上面的解决方案:

    sudo ln -s /usr/bin/gcc-4.4 /opt/cuda/bin/gcc
    sudo ln -s /usr/bin/g++-4.4 /opt/cuda/bin/g++

#12


2  

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

这适用于fedora 23。根据您的fedora版本,compat gcc存储库将略有不同。

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 the soft links as mentioned above assuming your cuda bin folder is in /usr/local/cuda/

现在,假设您的cuda bin文件夹在/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++

You should now be able to compile with nvcc without the gcc version error.

现在,您应该能够在没有gcc版本错误的情况下使用nvcc进行编译。

#13


1  

For people like me who get confused while using cmake, the FindCUDA.cmake script overrides some of the stuff from nvcc.profile. You can specify the nvcc host compiler by setting CUDA_HOST_COMPILER as per http://public.kitware.com/Bug/view.php?id=13674.

对于像我这样在使用cmake时感到困惑的人,FindCUDA。cmake脚本覆盖了来自nvcc.profile的一些内容。您可以通过将CUDA_HOST_COMPILER设置为http://public.kitware.com/Bug/view.php?id=13674来指定nvcc主机编译器。

#14


0  

In $CUDA_HOME/include/host_config.h, find lines like these (may slightly vary between different CUDA version):

在CUDA_HOME / include / host_config美元。h,找到像这样的线(在不同的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) <]
//...

Remove or change them matching your condition.

删除或更改它们与您的条件相匹配。

Note this method is potentially unsafe and may break your build. For example, gcc 5 uses C++11 as default, however this is not the case for nvcc as of CUDA 7.5. A workaround is to add

注意,此方法可能不安全,可能会破坏您的构建。例如,gcc 5使用c++ 11作为默认值,但是对于nvcc来说,这不是CUDA 7.5的情况。一个变通方法就是添加。

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

——Xcompiler =“- std = c + + 98”CUDA < = 6.5

or

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

- std = c + + 11 CUDA > = 7.0。

#15


0  

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

为了在Ubuntu 16.10上编译CUDA 8.0示例,我做到了:

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's 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 of not modifying the whole system or making symlinks to just the binaries (that could cause library linking problems.)

这样做的好处是不会修改整个系统,或者只将符号链接到二进制文件(这会导致库链接问题)。