I spent a while today digging through numerous “solutions” to getting the SDK examples to compile on Ubuntu 10.04 (yes, I realize it is currently unsupported). I didn’t really like the idea of downgrading my GCC version, and I didn’t want to play games with having multiple versions installed. It can’t be that hard to get it running under 4.4.3, can it?
It should be noted that I like to live dangerously and make my modifications directly to the installed files (not a copy of them in my home folder). I did make backups of the files I modified with a .bak extension. If you don’t like this method, feel free to substitute the necessary path changes. It should also be noted that I’m using the 64-bit version. I’m not sure how the results will work on 32-bit.
And of course a final note: most of these changes I pulled from various sources around the web. This document is a compilation of other people’s solutions to a bunch of problems. I don’t have a big old list of sources, but if anybody violently objects to my “research”, I can probably throw something together.
Let me know what mistakes I’ve made below and I’ll be sure to fix them. I hope this helps!
Compiling CUDA SDK examples on Ubuntu 10.04 (GCC 4.4.3)
[list=1]
Download and install the Ubuntu 9.04 CUDA toolkit and GPU Computing SDK code samples
Found here: http://developer.nvidia.com/object/cuda_3_0_downloads.html
Make sure to install as root (using “sudo” or “su” whichever you prefer). Install both to the same directory: /usr/local/cuda
The CUDA group
This isn’t necessary, but it’s a good way to handle directly modifying the files in /usr/local/cuda.
$ groupadd cuda
$ gpasswd -a <user> cuda
$ chgrp -R cuda /usr/local/cuda
$ chmod -R 775 /usr/local/cuda
where [font=“Courier New”][/font] is your non-root user account.
A few extra packages
I installing found these packages were necessary to compile, however you may already have some/all of them installed.
- (Fixes "[font="Courier New"]cannot find -lXi[/font]" error)
libxext-dev
libxi-dev
x11proto-xext-dev
- (Fixes "[font="Courier New"]cannot find -lXmu[/font]" error)
libice-dev
libsm-dev
libxt-dev
libxmu-headers
libxmu-dev
- (Fixes "[font="Courier New"]cannot find -lglut[/font]" error)
freeglut3-dev
libglut3-dev
You can install these packages the normal way (through [font=“Courier New”]apt-get[/font]).
The .bashrc file
There are a few variables needed for everything to go smoothly. These can be exported to the session (using [font=“Courier New”]export[/font], but I prefer to make them permanent). Using , add the following lines to the end of the file [font=“Courier New”]~/.bashrc[/font]
export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:/usr/local/cuda/lib:$LD_LIBRARY_PATH"
export CPLUS_INCLUDE_PATH="/usr/local/cuda/include"
export LIBRARY_PATH="/usr/lib/nvidia-current"
Editing NVIDIA’s files
Here’s where the magic really happens. There are four files that need to be changed. So fire up your favorite text editor (again) and let’s begin.
- [b]
/usr/local/cuda/C/common/common.mk[/b]
Add the no-inline flag to the first instance of NVCCFLAGS (currently line 92). If there are already some flags there (there shouldn’t be), just tack on the ones below. These changes (together with the next two) take care of the “inline function cannot be declared weak” errors.
Original:
NVCCFLAGS :=
Modified:
NVCCFLAGS += --compiler-options -fno-inline
Similarly, add the no-strict-aliasing flag to CXXFLAGS (line 158) and CFLAGS (line 159) in the Debug/release configuration:
Original:
CXXFLAGS += -D_DEBUG
CFLAGS += -D_DEBUG
Modified:
CXXFLAGS += -D_DEBUG -fno-strict-aliasing
CFLAGS += -D_DEBUG -fno-strict-aliasing
[b]
/usr/local/cuda/include/math_functions.h[/b]
In this file, there are four lines that need to be commented out. The declarations of “signbit” are the culprits (lines 413, 422, 427, and 440):
extern __host__ __device__ int __signbitd(double) __THROW;
...
extern __host__ __device__ int __signbit(double) __THROW;
...
extern __host__ __device__ int __signbitf(float) __THROW;
...
extern __host__ __device__ int __signbitl(long double) __THROW;
should become:
//extern __host__ __device__ int __signbitd(double) __THROW;
...
//extern __host__ __device__ int __signbit(double) __THROW;
...
//extern __host__ __device__ int __signbitf(float) __THROW;
...
//extern __host__ __device__ int __signbitl(long double) __THROW;
[b]
/usr/local/cuda/include/common_functions.h[/b]
This file has two lines that need to be commented out, the declarations of memset (line 59) and memcpy (line 62):
extern __host__ __device__ void * __cdecl memset(void *s, int c, size_t n) __THROW;
...
extern __host__ __device__ void * __cdecl memcpy(void *d, const void *s, size_t n) __THROW;
should become:
//extern __host__ __device__ void * __cdecl memset(void *s, int c, size_t n) __THROW;
...
//extern __host__ __device__ void * __cdecl memcpy(void *d, const void *s, size_t n) __THROW;
[b]
/usr/local/cuda/bin/nvcc.profile[/b]
This last modification fixes the problem about “builtin_std_arg”, which I believe is a symbol present in GCC 4.3, but not in 4.4, so we have to fake this symbol. The INCLUDES variable (lines 7) needs a few options tacked before the current ones (I’m not sure if the order actually matters).
INCLUDES += "-I$(TOP)/include" "-I$(TOP)/include/cudart" $(_SPACE_)
should become
INCLUDES += "-D__builtin_stdarg_start=__builtin_va_start" "-fno-inline" "-I$(TOP)/include" "-I$(TOP)/include/cudart" $(_SPACE_)
And finally…
cd /usr/local/cuda/C
make
And sit back and enjoy the (successful) compiler output. You can then have fun playing with the examples found in /usr/local/cuda/C/bin/linux/release . My favorite is probably “smokeParticles” .
EDIT: Looks like I had a typo in the nvcc.profile section. Where I had “-D__builtin_std_arg_start=_builtin_va_start", it should have been "-D__builtinstdarg_start=__builtin_va_start”. Fixed above.
EDIT: The default install directory for the SDK is in the user’s home directory. I’m not sure if this will work, but if you want to be sure, install both to /usr/local/cuda.