I had the same problem. Here is the easy solution.
The examples of CUDA (GPU Computing SDK) run correctly (You should have installed Nvidia GPU Computing SDK). Open the start menu and type "Browse CUDA SDK" in the text box (Hope you use win vista or seven).
The examples are in the src folder. The examples in this folder have solution in VS 2005, VS 2008 and VS 2010. They have all the initial settings set in this solution and projects and you can copy one of the examples and clean the code and run your own code. The only Problem is that their settings files are addressed locally (for example ../../common/lib/
). So you should run your project in exactly that src folder.
Also CUDA 4.0 and 4.1 had a CUDA Runtime option on Visual Studio's New project wizard. That was great and I don't know why did they eliminated this option on 4.2. If you couldn't run CUDA 4.2, CUDA 4.1 is a good option. (You can install Nvidia GPU SDK 4.1 and then uninstall it the Visual Studio optin will remain and work correctly)
Another option is to make a blank project and use this configuration (It is for CUDA 4.0 and the addresses in your computer may be different):
New -> Project -> Win32 Console Application
Name: "HelloCuda" -> OK -> Next -> Empty project -> Finish
Right Click the project HelloCuda -> Build Customizations
Click Find Existing and Navigate to CUDA 4.0.targets
C:\ProgramFiles\MSBuild\Microsoft.Cpp\v4. 0\BuildCustomizations\CUDA 4.0.targets
Now create a textfile and save it as HelloWorld with .cu Extension
Now you will have a file HelloWorld.cu
Add this file to the project HelloCuda
Right Click HelloWorld.cu -> Configuration Properties -> General -> Item Type -> CUDA C/C++
Now right click project HelloCuda -> Configuration Properties -> CUDA C/C++ -> Common -> Additional Include Directories
Add C:\Users\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\inc;
Now right click project HelloCuda -> Configuration Properties -> Linker -> General -> Additional Library Directories
Add C:\Users\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\common\lib;
Linker -> Input -> Additional Dependencies -> cudart.lib
Now write a sample CUDA C Program inside HelloWorld.cu and Compile.