Cuda compiler does not work with GCC 4.5 +

I am new to Cuda and I am trying to compile this simple test_1.cu file:

 #include <stdio.h> __global__ void kernel(void) { } int main (void) { kernel<<<1,1>>>(); printf( "Hello, World!\n"); return 0; } 

using this: nvcc test_1.cu

The output I get is:

 In file included from /usr/local/cuda/bin/../include/cuda_runtime.h:59:0, from <command-line>:0: /usr/local/cuda/bin/../include/host_config.h:82:2: error: #error -- unsupported GNU version! gcc 4.5 and up are not supported! 

my gcc --version:

 gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

How can I install the second version of gcc (4.4) along with 4.6 without downloading everything?

I found this old topic:

CUDA is not compatible with my gcc version

The answer was:

gcc 4.5 and 4.6 are not supported with CUDA - the code will not compile and the rest of the toolchain, 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 a second compiler (this will allow most distributions). There is the possibility of nvcc -compiler-bindir, which can be used to indicate an alternative to the compiler. Create a local directory and create symbolic links to the supported gcc version executables. Pass this local directory to nvcc via the -compiler-bindir option, and you should be able to compile CUDA code without using the rest of your system.

But I have no idea how to do this.

+2
source share
5 answers

Doing some research online shows several ways to solve this problem. I just tested the method found here: http://www.vectorfabrics.com/blog/item/cuda_4.0_on_ubuntu_11.04 , and it worked like a charm for me. This will help you install gcc 4.4 and create scripts to run this version with nvcc. If you prefer to use the method mentioned in your post, I would recommend that you follow this first link to install gcc4.4, and then create the symlinks mentioned in your post. Creating symbolic links on Linux is done using the ln command.

For instance:

  ln -s [source file/folder path] [linkpath] 

This link provides some examples of creating symbolic links on Ubuntu and Windows: http://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/ . Hope this indicates that you are in the right direction.

+2
source

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.

+3
source

I think you can try the new, beta version based on LLVM.

+1
source

Another way to make nvcc work with the compiler is not by default (unlike @Sluml's answer, it provides more flexibility):

First, like @Slump, you need to create the ~/local/gcc-4.4/ directory, and then create symbolic links there for the correct versions of gcc: for i in gcc gxx; do ln -s /usr/bin/${i}-4.4 ~/local/cudagcc/${i}; done for i in gcc gxx; do ln -s /usr/bin/${i}-4.4 ~/local/cudagcc/${i}; done for i in gcc gxx; do ln -s /usr/bin/${i}-4.4 ~/local/cudagcc/${i}; done . Now that you run nvcc -ccbin ~/local/gcc-4.4/ ... , nvcc will use the correct versions of gcc.

Here is a small CMake snippet to force nvcc using a special host compiler.

 option (CUDA_ENFORCE_HOST_COMPILER "Force nvcc to use the same compiler used to compile .c(pp) files insted of gcc/g++" OFF) if (${CUDA_ENFORCE_HOST_COMPILER}) set (CMAKE_GCC_TEMP_DIR "CMakeGCC") file(MAKE_DIRECTORY ${CMAKE_GCC_TEMP_DIR}) execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_C_COMPILER} ${CMAKE_GCC_TEMP_DIR}/gcc) execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_CXX_COMPILER} ${CMAKE_GCC_TEMP_DIR}/g++) set(CUDA_NVCC_FLAGS -ccbin ${CMAKE_GCC_TEMP_DIR} ${CUDA_NVCC_FLAGS}) endif() 
0
source

Link: I am upgrading my gcc from 4.4 to 4.6. Then I could not use nvcc to compile my code. Fortunately, using the method provided by the following link. I installed my default gcc compiler in gcc 4.4. Now I can compile the file using gcc4.4 or gcc4.6. terminate http://ubuntuguide.net/how-to-install-and-setup-gcc-4-1g4-1-in-ubuntu-10-0410-10

0
source

Source: https://habr.com/ru/post/1264339/


All Articles