CUDA by Example - Compiler Error Compiler throws errors when trying to compile the examples of the b

Good morning from Germany!

After setting up CUDA on Ubuntu 11.04 using these instructions (http://samiux.blogspot.com/2011/05/howto-nvidia-cuda-toolkit-40-on-ubuntu.html) I can run the CUDA samples of the SDK, but when trying to compile the examples of the book ‘CUDA By Example’ I get the following error-code:

[indent]r00t@r00t-EG41MF-US2H:~/Documents/cuda_by_example/chapter03$ nvcc hello_world.cu

In file included from /usr/lib/nvidia-cuda-toolkit/include/cuda_runtime.h:59:0,

             from <command-line>:0:

/usr/include/host_config.h:82:2: warning: #warning – unsupported GNU version! gcc 4.5 and up are not supported!

In file included from /usr/lib/nvidia-cuda-toolkit/include/cuda_runtime.h:59:0,

             from <command-line>:0:

/usr/include/host_config.h:82:2: warning: #warning – unsupported GNU version! gcc 4.5 and up are not supported!

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `HandleError(cudaError, char const*, int)’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x1e): undefined reference to `cudaGetErrorString’

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `start_thread(void* ()(void), void*)’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x198): undefined reference to `pthread_create’

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `end_thread(unsigned long)’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x1bb): undefined reference to `pthread_join’

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `destroy_thread(unsigned long)’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x1d5): undefined reference to `pthread_cancel’

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `__cudaUnregisterBinaryUtil()’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x242): undefined reference to `__cudaUnregisterFatBinary’

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `__device_stub__Z14float_to_colorPhPKf(unsigned char*, float const*)’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x26a): undefined reference to `cudaSetupArgument’

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x289): undefined reference to `cudaSetupArgument’

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `__device_stub__Z14float_to_colorP6uchar4PKf(uchar4*, float const*)’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x2fe): undefined reference to `cudaSetupArgument’

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x31d): undefined reference to `cudaSetupArgument’

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `__sti____cudaRegisterAll_46_tmpxft_00000954_00000000_4_hello_world_cpp1_ii_68d40520()’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x37e): undefined reference to `__cudaRegisterFatBinary’

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x3dc): undefined reference to `__cudaRegisterFunction’

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text+0x429): undefined reference to `__cudaRegisterFunction’

/tmp/tmpxft_00000954_00000000-13_hello_world.o: In function `cudaError cudaLaunch(char*)’:

tmpxft_00000954_00000000-1_hello_world.cudafe1.cpp:(.text.Z10cudaLaunchIcE9cudaErrorPT[cudaError cudaLaunch(char*)]+0x14): undefined reference to `cudaLaunch’

collect2: ld returned 1 exit status[/indent]

To me it seems like I did not set up my environment the right way so gcc or nvcc does not now where to get the CUDA function code, but I am a Linux and CUDA beginner and do not have any idea how to solve this problem. Any help is appreciated! LG r00t

You need to install gcc 4.4 (or 4.3). As the warning says, higher versions are not supported (yet).

Thanks for your reply!

Did not think about it any further because when compiling the Nvidia-examples this warning was displayed, too.

But I though uninstalled it and then installed gcc-4.4. NVCC etc. had to be uninstalled, too, so I wanted to reinstall them but I get this message suggesting to reinstall gcc-4.5 etc.:

[indent]r00t@r00t-EG41MF-US2H:~$ sudo apt-get install nvidia-cuda-toolkit

Reading package lists… Done

Building dependency tree

Reading state information… Done

The following extra packages will be installed:

dkms g++ gcc nvidia-current nvidia-current-dev nvidia-opencl-dev

Suggested packages:

g+±multilib gcc-multilib autoconf automake1.9 libtool flex bison gcc-doc

The following NEW packages will be installed:

dkms g++ gcc nvidia-cuda-toolkit nvidia-current nvidia-current-dev

nvidia-opencl-dev

0 upgraded, 7 newly installed, 0 to remove and 28 not upgraded.

Need to get 0 B/76.5 MB of archives.

After this operation, 206 MB of additional disk space will be used.

Do you want to continue [Y/n]?[/indent]

Hope there is a way to prevent the installation of those packages, funnily enough that gcc-4.5 etc. are suggested for this package…

After following another tutorial (http://hdfpga.blogspot.com/2011/05/install-cuda-40-on-ubuntu-1104.html), I got nvcc using gcc-4.4, but same thing as before, just without the gcc-version warnings:
[indent]r00t@r00t-EG41MF-US2H:~/Documents/cuda_by_example/chapter03$ nvcc hello_world.cu
/tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function HandleError(cudaError, char const*, int)': tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x1e): undefined reference to cudaGetErrorString’
/tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function start_thread(void* (*)(void*), void*)': tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x198): undefined reference to pthread_create’
/tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function end_thread(unsigned long)': tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x1bb): undefined reference to pthread_join’
/tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function destroy_thread(unsigned long)': tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x1d5): undefined reference to pthread_cancel’
/tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function __cudaUnregisterBinaryUtil()': tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x242): undefined reference to __cudaUnregisterFatBinary’
/tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function __device_stub__Z14float_to_colorPhPKf(unsigned char*, float const*)': tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x26a): undefined reference to cudaSetupArgument’
tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x289): undefined reference to cudaSetupArgument' /tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function __device_stub__Z14float_to_colorP6uchar4PKf(uchar4*, float const*)’:
tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x2fe): undefined reference to cudaSetupArgument' tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x31d): undefined reference to cudaSetupArgument’
/tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function __sti____cudaRegisterAll_46_tmpxft_000060ce_00000000_4_hello_world_cpp1_ii_68d40520()': tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x37f): undefined reference to __cudaRegisterFatBinary’
tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x3e0): undefined reference to __cudaRegisterFunction' tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text+0x430): undefined reference to __cudaRegisterFunction’
/tmp/tmpxft_000060ce_00000000-13_hello_world.o: In function cudaError cudaLaunch<char>(char*)': tmpxft_000060ce_00000000-1_hello_world.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x14): undefined reference to cudaLaunch’
collect2: ld returned 1 exit status[/indent]
What the hell could I be doing wrong?

Another question:
Does it matter, where I put “cuda_by_example”?

After reading this : http://stackoverflow.com/questions/4786764/linking-in-library-that-contains-reference-to-cuda-kernel
I did the following:
//edited

  1. call “nvcc -c hello_world.cu”
  2. call “g+±4.4 -lcudart hello_world.o -o hello_world”
    One gets an executable that one can run and it finally says “Hello World” GOD DAMMIT :D