If you get an error like

/usr/include/c++/4.4/ext/atomicity.h(46): error: identifier “__sync_fetch_and_add” is undefined

when trying to compile your CUDA project which is using FindCUDA.cmake, there is quite an easy solution for this. NVCC does not really like the latest versions of gcc or g++, so you have to try it with version 4.3 of both of them.

So the first step is installing gcc-4.3 and g++-4.3, which should be in the repositories of most Linux distributions, though this may have been simply upgraded to 4.4. On Ubuntu Karmic as well as Debian Squeeze it has been possible to additionaly install the older version in parallel via aptitude.

After having these installed, I first tried to modify my CMakeLists.cmake file by adding this:

set(CMAKE_C_COMPILER “gcc-4.3″)
set(CMAKE_CXX_COMPILER “g++-4.3″)

Hoping that this does the job, I was quite disappointed, as it didn’t. You have to explicitly set the flags which are passed to NVCC, which actually seems to always use the files “gcc” and “g++”. Fortunately, you can pass it a flag which tells where to search for those files. So you can create symlinks “gcc” and “g++” to the 4.3-versions of the tools in a directory of your choice (e.g. /usr/local/bin/gnuc4.3) and add the following line to your CMakeLists.cmake file:

set(CUDA_NVCC_FLAGS –compiler-bindir /usr/local/bin/gnuc4.3)

This should probably be set after find_package(CUDA) has been called. Works like a charm for me, finally :)

One Response to “CUDA 2.3, FindCUDA.cmake and wrong gcc/g++ versions (4.4 and later)”

  1. cache says:

    Thanks! Apparently it worked without –compiler-bindir

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2010 P=NP! Suffusion WordPress theme by Sayontan Sinha