About Me

A Computer Enthusiast who's learning as much as I can, while attempting to share and re-distribute the knowledge! Enjoy! :D

Tuesday, June 1, 2010

Quickstart: CUDA using Bayreuth University CUDA Toolchain for Eclipse

I've been trolling through Google for a simple solution in integrating CUDA with Eclipse, and found a University which built an Eclipse plugin. This is a fantastic solution because my previous attempts required me to create my own Makefile (which partially defeats the purpose of using Eclipse!)

Here is my Quickstart for the plugin

  • A fully functional C/C++ working environment (within the Eclipse IDE and on the command line)
  • A fully functional CUDA environment (including the CUDA Driver, Toolkit, and SDK
  • This assumes you are using OS X (Linux should be quite similar)
1. Install the Plugin (Trivial)
2. Add nvcc to your Path
  • Go to Eclipse --> Preferences
  • Click on C/C++ --> Environment
  • Under Environment variables to set --> click Add
  • Name = PATH (Note: Make sure PATH are all upper case)
  • Value = /usr/local/cuda/bin
  • Apply and OK
3. Create a new CUDA Project and Setup Compile and Build Environment
  • Ctrl + mouse click --> New --> C++ project
  • Under Project type box --> Executable --> select Empty Project
  • Name your project
  • Uncheck the following: Show project types and toolchains only if they are supported on the platform
  • Under Toolchains --> select CUDA Toolchain
  • Click Next
  • Click on Advanced Settings
  • Under C/C++ Build -->Environment --> Confirm PATH is set from previous step (should be USER: PREFS under Origin Column)
  • Under C/C++ Build --> Settings --> Tool Settings Tab --> CUDA NVCC Compiler --> Includes --> add /usr/local/cuda/include
  • Under C/C++ Build --> C++ Linker --> change Command from g++ to nvcc
  • Under C/C++ Build --> C++ Linker --> Libraries --> add cudart to Libraries (-l) and add /usr/local/cuda/lib to Library search path (-L)
  • Apply and OK
At this point you should have a fully functional CUDA Eclipse environment to develop CUDA Applications. Drop in some pre-built (non SDK dependent code) into the project and build it. If you want to run some of the SDK dependent code (located in /Developer/GPU Computing/C/bin/darwin/release), please follow the instructions located at Life Of A Programmer Geek.

*** UPDATE ***

When attempting to build my project, I was getting the following error message during the build phase:

make all
Building target: CUDAToolchainProject
ld: unknown option: -oCUDAToolchainProject
I tracked the problem down to not having "whitespaces" in between the following:
  • This is located at --> --> Properties --> C/C++ Build --> Settings --> C++ Linker
  • Under Expert Settings --> Command line pattern
To mitigate the problem ... just add "whitespaces" in between the following:
However, I came across another error during the build phase:

Invoking: C++ Linker
g++ -L/usr/local/cuda/lib -o "CUDAToolchainProject" ./src/cu_mandelbrotCUDA_D.o ./src/cu_mandelbrotCUDA_H.o -lcudart
ld: warning: in ./src/cu_mandelbrotCUDA_D.o, file is not of required architecture
ld: warning: in ./src/cu_mandelbrotCUDA_H.o, file is not of required architecture
ld: warning: in /usr/local/cuda/lib/libcudart.dylib, file is not of required architecture
Undefined symbols:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [CUDAToolchainProject] Error 1

To mitigate this problem ... I changed the C++ Linker from g++ to nvcc
  • Properties --> C/C++ Build --> Settings --> C++ Linker
  • Command --> change from g++ to nvcc

The build phase completed successfully and an executable was generated!

The next steps are optional (If you want to follow Eclipse's general project structure, follow the next steps

4. Create Source Folders (Trivial)
  • Ctrl + mouse click --> New --> Source Folder
  • Name your folder


1. Bayreuth University Website
  • http://www.ai3.inf.uni-bayreuth.de/software/eclipsecudaqt/updates
2. NVIDIA CUDA forum: thread 160564
  • http://forums.nvidia.com/index.php?showtopic=160564
3. Life Of A Programmer Geek
  • http://lifeofaprogrammergeek.blogspot.com/2008/07/using-eclipse-for-cuda-development.html
4. Trial & Error


  1. I wanted to first say thank you for the excellent documentation here!

    I'd also like to give a little in return.
    Instead of or in addition to adding -L/usr/local/cuda/lib as a linker option as you describe above.

    You can add -Xlinker -rpath,/usr/local/cuda/lib.

    # Under C/C++ Build --> C++ Linker --> Libraries --> Miscellaneous --> add -rpath,/usr/local/cuda/lib in the Other options(-Xlinker [option]) field.

    This allows the dynamic library location to be baked into your binary so that users who don't want to (or for stability reason's can't) define DYLD_LIBRARY_PATH are covered. This also helps with eclipse+CDT and any launch configurations that aren't picking up this environment variable.

  2. hi can anybody help me with this.....being tryin it for quite sum time now....followed all the exact same procedure given above...heres the error i get on building,

    make all
    i686-apple-darwin10-g++-4.2.1: ../first.cu: linker input file unused because linking not done
    Building file: ../first.cu
    Invoking: C++ Compiler
    g++ -O2 -g -Wall -c -fmessage-length=0 -o "first.o" "../first.cu"
    Finished building: ../first.cu

    Building target: cuda_test
    Invoking: C++ Linker
    nvcc -L/usr/local/cuda/lib -o "cuda_test" ./first.o -lcudart
    i686-apple-darwin10-g++-4.2.1: ./first.o: No such file or directory
    make: *** [cuda_test] Error 1

    The linker is not able to find the .o file for some reason...Any idea on this.?

  3. OK i figured it out..... I feel this might be of help to other users as well, so heres my part of the cookie..

    Above mentioned setting configurations are perfect, but here are a few missing pieces.
    1) For some reason even after setting "Cuda Toolchain" in the Properties-->C++-->Tool Chain Editor, the plugin is unable to identify a .cu file. I have also included *.cu in Eclipse-->Preferences-->C/C++ File types..
    In order to get around this, you need to individually right click the .cu file, Properties-->C/C++ Build/-->ToolChain Editor--> Select Current tool as NVCC Compiler...

    2)Also the points mentioned by sschluet about setting rpath in the -Xlinker field are correct and they were the missing parts in my jigsaw... If that is not set, this is the msg ull get when u try to run ur executable thru eclipse:

    "dyld: Library not loaded: @rpath/libcudart.dylib
    Referenced from: /Users//Documents/workspace/cuda_test/Default/cuda_test
    Reason: image not found"
    Setting -rpath and /usr/local/cuda/lib in the -Xlinker option under the C++ Linker-->Miscellaneous option worked out perfect. Thanks sschulet!

    3) Finally since I spent many many MANY hours on getting this done, I feel displaying my final SUCCESSFUL build console message might be a good cue for those trying the same:
    Your build message should read:

    make all
    Building file: ../first.cu
    Invoking: CUDA NVCC Compiler
    nvcc -c -o "cu_first.o" "../first.cu" && \
    echo -n 'cu_first.d' ./ > 'cu_first.d' && \
    nvcc -M "../first.cu" >> 'cu_first.d'
    Finished building: ../first.cu

    Building target: cuda_test
    Invoking: C++ Linker
    nvcc -L/usr/local/cuda/lib -Xlinker -rpath -Xlinker /usr/local/cuda/lib -o "cuda_test" ./cu_first.o -lcudart
    Finished building target: cuda_test

  4. First, thanks for your post, it helped a lot... I'd like to add two comments, as I needed to add two additional steps to the procedure to make it work. Project build worked fine, but to run it:

    1) Eclipse couldn't find the executable: I needed to introduce the location manually:
    Run > Run Configurations
    click the icon for new project
    Then I could introduce (Main Tab, C/C++ Application) the folder where the executable was.

    2) I also got the error
    dyld: Library not loaded: @rpath/libcudart.dylib

    In order to correcti it
    Run > Run Configurations, then go to the Environment tab and introduce manually after pressing New the variable DYLD_LIBRARY_PATH with the value /usr/local/cuda/lib

  5. By the way: the debugging mode is still not running for me, and can just compile and execute. Wonder if I'm doing something wrong or it is actual extent of the plugin...

  6. Hello,

    Thanks for your excellent post, I finally got the eclipse CUDA plugin from Bayreuth University to "build".

    My problem is that the eclipse tells me that it cannot resolve CUDA functions and variables, but otherwise it successfully builds an executable. I've wrestled with this issue, trolling the forums, and even including and as one of the entries recommended, to no avail. Is there a way to have Eclipse recognized CUDA functions, variables, etc.? I am using Eclipse Indigo (latest version of Eclipse?) on a MacBook Pro running Snow Leopard.

    Many thanks.