Programing

CUDA가 내 gcc 버전과 호환되지 않습니다.

lottogame 2020. 9. 17. 18:51
반응형

CUDA가 내 gcc 버전과 호환되지 않습니다.


CUDA SDK와 함께 제공되는 일부 예제를 컴파일하는 데 문제가 있습니다. 개발자 드라이버 (버전 270.41.19)와 CUDA 툴킷을 설치 한 다음 마지막으로 SDK (모두 4.0.17 버전)를 설치했습니다.

처음에는 전혀 컴파일되지 않았습니다.

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

81 : /usr/local/cuda/include/host_config.h에서 담당하는 줄을 발견하고 다음과 같이 변경했습니다.

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

그 시점부터 컴파일 할 예제 중 몇 개만 얻었으며 다음과 같이 중지됩니다.

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

일부 예제가 컴파일되면 이것이 드라이버 문제가 아니라 지원되지 않는 gcc 버전과 관련이 있다고 생각합니다. gcc4.6은이 시점에서 전체 시스템을 종속성으로 사용하므로 다운 그레이드는 옵션이 아닙니다.


이미 지적했듯이 nvcc는 gcc 4.4에 의존합니다. nvcc 설치로 생성 된 bin 디렉토리에 소프트 링크를 추가하여 컴파일러 매개 변수를 전달하지 않고도 올바른 버전의 gcc를 사용하도록 nvcc를 구성 할 수 있습니다.

기본 cuda 바이너리 디렉토리 (설치 기본값)는 / usr / local / cuda / bin이며,이 디렉토리에서 올바른 gcc 버전에 대한 소프트 링크를 추가하는 것으로 충분합니다.

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


gcc 4.5 및 4.6은 CUDA에서 지원되지 않습니다. 코드가 컴파일되지 않고 cuda-gdb를 포함한 나머지 도구 모음이 제대로 작동하지 않습니다. 사용할 수 없으며 제한 사항은 협상 할 수 없습니다.

유일한 해결책은 gcc 4.4 버전을 두 번째 컴파일러 로 설치하는 것입니다 (대부분의 배포판에서는이를 허용합니다). --compiler-bindir대체 컴파일러를 가리키는 데 사용할 수있는 nvcc에 대한 옵션 이 있습니다. 로컬 디렉토리를 만든 다음 지원되는 gcc 버전 실행 파일에 대한 심볼릭 링크를 만듭니다. --compiler-bindir옵션을 통해 해당 로컬 디렉토리를 nvcc로 전달 하면 나머지 시스템에 영향을주지 않고 CUDA 코드를 컴파일 할 수 있습니다.


수정 :

이 질문과 답변은 CUDA 4와 관련이 있습니다. 작성된 이후 NVIDIA는 최신 CUDA 툴체인 릴리스에서 최신 gcc 버전에 대한 지원을 계속 확장했습니다.

  • CUDA 4.1 릴리스부터 gcc 4.5가 지원됩니다. gcc 4.6 및 4.7은 지원되지 않습니다.
  • CUDA 5.0 릴리스부터 gcc 4.6이 지원됩니다. gcc 4.7은 지원되지 않습니다.
  • CUDA 6.0 릴리스부터 gcc 4.7이 지원됩니다.
  • CUDA 7.0 릴리스부터 gcc 4.8은 Ubuntu 14.04 및 Fedora 21에서 4.9 지원과 함께 완전히 지원됩니다.
  • CUDA 7.5 릴리스부터 gcc 4.8이 완전히 지원되며 Ubuntu 14.04 및 Fedora 21에서 4.9를 지원합니다.
  • CUDA 8 릴리스부터 gcc 5.3은 Ubuntu 16.06 및 Fedora 23에서 완전히 지원됩니다.
  • CUDA 9 릴리스부터 gcc 6은 Ubuntu 16.04, Ubuntu 17.04 및 Fedora 25에서 완벽하게 지원됩니다.
  • CUDA 9.2 릴리스는 gcc 7에 대한 지원을 추가합니다.

현재 (CUDA 10 기준) CUDA에는 gcc 8 지원이 없습니다.

NVIDIA는 최근 CUDA 릴리스에 대해 지원되는 컴파일러 및 OS 매트릭스가 포함 된 매우 유용한 표를 여기 에 추가했습니다 .


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

먼저 gcc 및 g ++ 8을 설치해야합니다.

sudo apt install gcc-8 g++-8

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

먼저 gcc 및 g ++ 7을 설치해야합니다.

sudo apt install gcc-7 g++-7

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:

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

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

sudo apt install gcc-5 g++-5

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:

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

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

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:

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

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:

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.


If using cmake for me none of the hacks of editing the files and linking worked so I compiled using the flags which specify the gcc/g++ version.
cmake -DCMAKE_C_COMPILER=gcc-6 -DCMAKE_CXX_COMPILER=g++-6 ..

Worked like charm.


This works for fedora 23. The compat gcc repositories will be slightly different based 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 the soft links as mentioned above assuming 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++

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


Gearoid Murphy's solution works like a charm. For me I had two directories for 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.


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.

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 nvcc.profile varies, but it should be in the same directory as the nvcc executable itself.

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.


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


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.


I had to install the older versions of 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:

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

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

//...
#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

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

or

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


To compile the 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'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.)


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

참고URL : https://stackoverflow.com/questions/6622454/cuda-incompatible-with-my-gcc-version

반응형