Compiling CUDA SDK examples on Ubuntu 10.04 without downgrading GCC

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.

firstly, thankyou very much for posting this!

I think I followed your instructions to the letter, but I get the following error at fluidsGL:

[codebox]make[1]: Entering directory `/usr/local/cuda/C/src/fluidsGL’

…/…/common/inc/nvShaderUtils.h(96): warning: result of call is not used

…/…/common/inc/nvShaderUtils.h(226): warning: result of call is not used

…/…/common/inc/nvShaderUtils.h(96): warning: result of call is not used

…/…/common/inc/nvShaderUtils.h(226): warning: result of call is not used

…/…/common/inc/nvShaderUtils.h(96): warning: result of call is not used

…/…/common/inc/nvShaderUtils.h(226): warning: result of call is not used

/usr/include/c++/4.4/x86_64-linux-gnu/bits/c++locale.h: In function ‘int std::__convert_from_v(__locale_struct* const&, char*, int, const char*, …)’:

/usr/include/c++/4.4/x86_64-linux-gnu/bits/c++locale.h:86: error: ‘__builtin_stdarg_start’ was not declared in this scope

…/…/common/inc/nvShaderUtils.h: In function ‘GLuint nv::CompileGLSLShaderFromFile(GLenum, const char*)’:

…/…/common/inc/nvShaderUtils.h:96: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result

…/…/common/inc/nvShaderUtils.h: In function ‘GLuint nv::CompileASMShaderFromFile(GLenum, const char*)’:

…/…/common/inc/nvShaderUtils.h:226: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result

make[1]: *** [obj/x86_64/release/fluidsGL.cu.o] Error 1

make[1]: Leaving directory `/usr/local/cuda/C/src/fluidsGL’

make: *** [src/fluidsGL/Makefile.ph_build] Error 2[/codebox]

Looks like I had a typo in the nvcc.profile section. For some reason, I added an extra underscore in the compile options. See the edit note at the bottom of the post. I suspect this will fix your problem.

I think it should be (in default SDK install) :

Yeah, you’re right. The SDK default goes to the home directory. My guide was written for both to be installed to /usr/local/cuda. I haven’t tried keeping the SDK in home yet.

follow your guide , I meet a “/usr/bin/ld: cannot find -lGL” error when make the SDK samples.

then I create a file:

sudo gedit /etc/ld.so.conf.d/cuda.conf

add:

/usr/local/cuda/lib64

but still meat that error. so I check the my libGL files:

file /usr/lib/libGL*

to fix(according http://forums.nvidia.com/index.php?s=&…amp;p=1062939):

sudo rm /usr/lib/libGL.so

sudo ln -s /usr/lib/libGL.so.1 /usr/lib/libGL.so

now, all the SDK samples can be build and run fine :)

@cho: If you remove the configuration file in /etc/ld.so.conf.d/ , can you compile? This will identify whether it was just a broken library or not.

nearly there!

I still get this error when I make the C examples:

[codebox]make[1]: Entering directory `/usr/local/cuda/C/src/threadMigration’

/usr/bin/ld: cannot find -lcuda

collect2: ld returned 1 exit status

make[1]: *** […/…/bin/linux/release/threadMigration] Error 1

make[1]: Leaving directory `/usr/local/cuda/C/src/threadMigration’

make: *** [src/threadMigration/Makefile.ph_build] Error 2[/codebox]

but I can make individual examples and I could also make the OpenCL examples. Great!

edit: actually I just tried reinstalling the SDK to the my /home/folder/ and it all compiled just fine!

Thanks for your perfect tutorial on ubuntu 10.04. I have the same ubuntu as yours but
when i try to do as you described

i still have an error like this:
make -C src/MonteCarlo/
make[1]: Entering directory `/home/cheng/NVIDIA_GPU_Computing_SDK/C/src/MonteCarlo’
MonteCarlo.cpp:33: warning: deprecated conversion from string constant to ‘char*’
MonteCarlo.cpp: In function ‘int main(int, char**)’:
MonteCarlo.cpp:121: warning: ‘sumReserve’ may be used uninitialized in this function
nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
make[1]: *** [obj/i386/release/MonteCarlo_SM10.cu_10.o] Error 255

What is the single input file is required for a non-link phase when an outputfile is specified

finally a complete solution. thanks a lot.

finally a complete solution. thanks a lot.

BTW, the 3.1 version seems to have fixed most of these problems.

BTW, the 3.1 version seems to have fixed most of these problems.

I meet a error when making “transpose” using CUDA 3.1 on ubuntu 10.04. how do u fix this problem ?

I meet a error when making “transpose” using CUDA 3.1 on ubuntu 10.04. how do u fix this problem ?

I have encountered a similar problem trying to port CUDA 3.1 to arch linx. One idea is that the original fixes were for CUDA SDK 3.0…not sure if they still apply for CUDA 3.1.

I have encountered a similar problem trying to port CUDA 3.1 to arch linx. One idea is that the original fixes were for CUDA SDK 3.0…not sure if they still apply for CUDA 3.1.

After battling for a few hours I finally have Toolkit/SDK 3.1 compiling on Ubuntu 10.04 64bit. This thread was the key! What follows is the minimum required effort after doing a normal install of driver/toolkit/SDK.

Solution for cannot find -lXi -lXmu -lglut: Install missing libraries.

sudo apt-get install libxext-dev libxi-dev x11proto-xext-dev libice-dev libsm-dev libxt-dev libxmu-headers libxmu-dev freeglut3-dev libglut3-dev

Solution for cannot find -lGL: There is a broken link for libGL.so, replace it.

sudo rm /usr/lib/libGL.so; sudo ln -s /usr/lib/libGL.so.1 /usr/lib/libGL.so

Solution for weird errors in surface_functions.h: g++ 4.4 does a better job of checking for sloppy function calls in C++. I don’t use C++ so I’ll just skip this. Find the first instance of NVCCFLAGS in NVIDIA_GPU_Computing_SDK/C/common/common.mk and change it to

NVCCFLAGS	   := --compiler-options -fpermissive

After battling for a few hours I finally have Toolkit/SDK 3.1 compiling on Ubuntu 10.04 64bit. This thread was the key! What follows is the minimum required effort after doing a normal install of driver/toolkit/SDK.

Solution for cannot find -lXi -lXmu -lglut: Install missing libraries.

sudo apt-get install libxext-dev libxi-dev x11proto-xext-dev libice-dev libsm-dev libxt-dev libxmu-headers libxmu-dev freeglut3-dev libglut3-dev

Solution for cannot find -lGL: There is a broken link for libGL.so, replace it.

sudo rm /usr/lib/libGL.so; sudo ln -s /usr/lib/libGL.so.1 /usr/lib/libGL.so

Solution for weird errors in surface_functions.h: g++ 4.4 does a better job of checking for sloppy function calls in C++. I don’t use C++ so I’ll just skip this. Find the first instance of NVCCFLAGS in NVIDIA_GPU_Computing_SDK/C/common/common.mk and change it to

NVCCFLAGS	   := --compiler-options -fpermissive

It works ! Thank you :)