Ensure you have Microsoft Visual Studio 2010 installed before you install the CUDA toolkit, if you have already installed the CUDA toolkit and have not yet installed Visual Studio then un-install it before continuing (not doing so will result in Visual Studio integration not functioning!)

Step 1: Setup your Environment
1. Install Microsoft Visual C++ 2010 (you can download Microsoft Visual C++ 2010 Express for free from

2. Install the latest Nvidia driver from

3. Install CUDA toolkit and CUDA SDK from here

Step 2: Test your Environment:
The best way to do this is to run an existing Nvidia sample project.

1. build and run one of the sample project that come with the SDK (if the default installation path was used then these are located in C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\src, deviceQuery is a good sample to run)

2. if you get get the error: “The result “” of evaluating the value “$(CudaBuildTasksPath)” of the “AssemblyFile” attribute in element is not valid”.
Then download the bug fix from the nvidia website, found here:

Step 3: Create your own CUDA Project
1. Open Microsoft Visual C++ 2010

2. Create a new empty project: file->new->project, select win32 console application. Ensure to select empty project see screenshot below:Cuda Example Image 00

3. Right click on the source files folder and create a new cpp file (add->new item)

4. Add a main function and Add #include and in the main function call cudaError_t error_id = cudaGetDeviceCount(&deviceCount);
The include and line of code will be underlined in red because the project cannot find the .h file. So your cpp should now look like this:
Cuda Example Image 01

5. We now need to get rid of those compile errors from the previous step. Rename the .cpp file to .cu

6.Now the included .h file and the call to the CUDA function should no longer give compile errors. To get syntax highlighting working for .cu files. tools->options->text editor->file extension type .cu in input box, click add press ok and restart Visual Studio.

7. If you now compile the project you will get compile errors, “LNK” errors, To fix this. Right click on the project, Build Customizations, Tick the CUDA check box and click ok.
Cuda Example Image 02
Cuda Example Image 03

8. If you compile you will still get compile errors, we need to add the path to the CUDA libraries to fix these issues, to do this: right click the project, properties -> configuration properties -> linker -> input, add cudart.lib; to Additional Dependencies
Cuda Example Image 04

9. You will now be able to compile and run your application within visual studio. But, there is another issue we need to resolve. If you go look in the output directory (release/debug) you will see that a .exe was not generated, there is only a .obj file and some other files. To fix this, right click on the .cu file you created click properties. Selected General and set the item type to CUDA C/C++ (see pic below)

(this will also update the project properties menu to show CUDA specific information).

Your project should now compile and run.


  Hi, I'm Steven and the author of this blog
  Follow me on or