2

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 a second version of gcc (4.4 -) along with 4.6 without messing everything up?

I found this old topic:

CUDA incompatible with my gcc version

the answer was:

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.

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 the 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 effecting the rest of your system.

But I have no idea how to do it

Community
  • 1
  • 1
Test Test
  • 2,831
  • 8
  • 44
  • 64
  • Not entirely true. gcc 4.5 works just fine. It requires you to comment out the error generating code from the header file. gcc 4.6 is another issue which is not supported by cuda 4.0. However I am hopeful the new cuda 4.1 (due in early January) will be compatible with 4.6 – Pavan Yalamanchili Dec 22 '11 at 16:17

5 Answers5

3

In my case I didn't have root rights, so I couldn't fully replace the current gcc (4.7) with the older version 4.4 (which I think would be a bad alternative). Although I did have rights where CUDA was installed. My solution was to create an extra folder (e.g. /somepath/gccfornvcc/), wherever I had rights, then to create a link to an nvcc accepted compiler. I already had gcc 4.4 available (but you can install it, without removing your 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 . There you just need to add the following line:

compiler-bindir = /somepath/gccfornvcc

And that will make nvcc use the proper compiler. This helps keeping the system in a proper state, keeping the newest compiler, but nvcc (only nvcc) will use the old compiler version.

kennethfm
  • 91
  • 1
  • 1
  • 8
2

Doing some research online shows several methods for accomplishing this task. 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. It steps you through installing gcc 4.4 and creating scripts to run that version with nvcc. If you prefer trying the method mentioned in your post I'd recommend following that first link to install gcc4.4 and then create symbolic links as mentioned in your post. Creating symbolic links in Linux is accomplished by using the 'ln' command.

For example:

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

This link gives a few examples of creating symbolic links on both Ubuntu and Windows: http://www.howtogeek.com/howto/16226/complete-guide-to-symbolic-links-symlinks-on-windows-or-linux/. Hopefully that points you in the right direction.

ramsey_tm
  • 792
  • 5
  • 7
1

I guess you may try the new, beta, version, that based on LLVM.

J-16 SDiZ
  • 26,473
  • 4
  • 65
  • 84
0

Another way to make nvcc work with non-default compiler (unlike @Sluml's answer, it allows more flexibility):

At first, just like @Slump proposed, you need to create directory ~/local/gcc-4.4/, and then create there symlinks for right versions of gcc: for i in gcc gxx; do ln -s /usr/bin/${i}-4.4 ~/local/cudagcc/${i}; done. Now when you run nvcc -ccbin ~/local/gcc-4.4/ ... nvcc will use correct versions of gcc.

Here is small CMake snippet of forcing nvcc use specific 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()
aland
  • 4,829
  • 2
  • 24
  • 42
0

Reference: I update my gcc from 4.4 to 4.6. Then I could not use nvcc to compile my code. Luckily, by using the method provided by the following link. I set my default gcc compiler back to gcc 4.4. Now, I could compile file using either gcc4.4 or gcc4.6. quit cool http://ubuntuguide.net/how-to-install-and-setup-gcc-4-1g4-1-in-ubuntu-10-0410-10

Xiao
  • 1