CUDA 2.3 on Ubuntu 9.10

In case you’ve been pulling hairs over this like me, NVIDIA’s CUDA 2.3 doesn’t work on any platforms that ship with gcc 4.4, here’s how to make it work without having to uninstall gcc 4.4 (which is what most of the NVIDIA forum posts suggest).

NVIDIA seems to hardcode “/usr/bin/gcc” in their tools, in spite of providing hand-written makefiles with the option of changing CC. So even if one installs gcc-4.3 and says “CC=gcc-4.3” in various different places over their own handwritten makefiles (because why would their own makefiles respect their conventions instead of simply overwriting the options? Much more fun to be had that way), one still gets this:

simpleGL.cpp: In function ‘void runAutoTest()’:
simpleGL.cpp:349: warning: deprecated conversion from string constant to ‘char*’
/usr/include/string.h:43: error: inline function ‘void* memcpy(void*, const void*, size_t)’ cannot be declared weak
/usr/include/string.h:64: error: inline function ‘void* memset(void*, int, size_t)’ cannot be declared weak
/usr/include/bits/string3.h:49: error: inline function ‘void* memcpy(void*, const void*, size_t)’ cannot be declared weak
/usr/include/bits/string3.h:78: error: inline function ‘void* memset(void*, int, size_t)’ cannot be declared weak
/usr/local/cuda/bin/../include/common_functions.h:59: error: inline function ‘void* memset(void*, int, size_t)’ cannot be declared weak
/usr/local/cuda/bin/../include/common_functions.h:62: error: inline function ‘void* memcpy(void*, const void*, size_t)’ cannot be declared weak
/usr/local/cuda/bin/../include/math_functions.h:412: error: inline function ‘int __signbit(double)’ cannot be declared weak
/usr/local/cuda/bin/../include/math_functions.h:417: error: inline function ‘int __signbitf(float)’ cannot be declared weak
/usr/include/bits/mathcalls.h:350: error: inline function ‘int __signbit(double)’ cannot be declared weak
/usr/include/bits/mathcalls.h:350: error: inline function ‘int __signbitf(float)’ cannot be declared weak
/usr/include/bits/mathcalls.h:350: error: inline function ‘int __signbitl(long double)’ cannot be declared weak
/usr/include/bits/mathinline.h:36: error: inline function ‘int __signbitf(float)’ cannot be declared weak
/usr/include/bits/mathinline.h:42: error: inline function ‘int __signbit(double)’ cannot be declared weak
/usr/include/bits/mathinline.h:48: error: inline function ‘int __signbitl(long double)’ cannot be declared weak
/usr/local/cuda/bin/../include/math_functions.h:442: error: inline function ‘int __signbitl(long double)’ cannot be declared weak
make[1]: *** [obj/release/simpleGL_kernel.cu.o] Error 255

which are errors related to gcc 4.4 (sensibly) not liking inline functions declared as weak symbols. However, how is nvcc even seeing gcc 4.4, you ask? Ah, someone hardcoded /usr/bin/gcc elsewhere in nvcc. So you have to use the command-line option –compiler-bindir (incidentally, you have to specify the full binary path, and not the directory, despite the option being called “…-bindir”). So add “–compiler-bindir=/usr/bin/gcc-4.3” to NVCCFLAGS in your makefiles,

$ sudo apt-get install g++-4.3

And then it all works. NVIDIA, your Linux driver team kicks ass (and is the primary reason I have been buying NVIDIA since the TNT2). Please tell them to have a chat with the CUDA people 🙂

Advertisements

12 responses to “CUDA 2.3 on Ubuntu 9.10

  1. If you just want to use gcc 4.3 for everything, you can change what version is /usr/bin/gcc using the update-alternatives command (or the galternatives GUI)

  2. Nice spot! working like a sharm on Ubuntu 9.10 amd64 with CUDA toolkit 2.3.

  3. Thanks so much for posting this! I am a relative novice to CUDA, but have installed it several times over the past year, and this GCC 4.4 problem was very puzzling for me. Now I can compile everything in the SDK. This was very helpful!

  4. can anyone please explain me how to use this command, as i am new to cuda and ubuntu..

    –compiler-bindir=/usr/bin/gcc-4.3

    i am also facing the same problem in ubuntu with the make command .. and the errors are the same
    “can not be declared weak”
    ..so can anyone help me please….

  5. This works, thanks!

  6. amit:
    In your “yourpath”/NVIDIA_GPU_Computing_SDK/C/common, edit the common.mk.
    Add this line:
    NVCCFLAGS += –compiler-bindir=/usr/bin/gcc-4.3
    somewhere after NVCCFLAGS is decleared.

    I had some trouble with copy paste as the long – before compiler is actually – x2 ( – -compiler)

    At least this worked for me after failing in some other guides.

  7. Hi
    Thanks for the fix, this got CUDA working on my Linux Mint 8, but has anyone got GPUmat working on linux Mint 8 / Ubuntu 9.10 (with Matlab) , and if so how?

  8. Asath doesn’t work….

  9. argiris: I am pretty new to Ubuntu and CUDA, but today I installed Ubuntu 9.10 and CUDA 2.3 on another computer aswell, followed this procedure and it worked fine.

    What is your error? Maybe you forgot something.

  10. Asath’s solution worked for me. I really didn’t want to uninstall the newest gcc. 🙂

  11. I got errors despite that. Needed to install libxi-dev, libxmu and libglut

  12. Hello,

    Thanks for the post. I’ve just stumbled across this from a google search and voila, problem solved 🙂

    p.s. I’m on lucid (10.04)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s