As a proud owner of nVidia graphic card (and being some kind of a fan of nVidia for their effort into graphics programming) I decided to go and try CUDA. At the moment the newest version is 2.1. The first thing after installing something you want to try out is to go and look at the samples, right? The same thing I thought, but unfortunately there were some problems compiling samples from nVidia CUDA SDK.
I tried to compile one of the simplest samples, but I instead of success I saw error message:
1>—— Build started: Project: cudaOpenMP, Configuration: Debug Win32 ——
1>Compiling with CUDA Build Rule…
1>"C:Program FilesnVidiaCUDAbinnvcc.exe" -arch sm_10 -ccbin "C:Program FilesMicrosoft Visual Studio 9.0VCbin" -Xcompiler "/EHsc /W3 /nologo /Od /Zi /MTd " -IC:Program FilesnVidiaCUDAinclude -I../../common/inc -maxrregcount=32 –compile -o DebugcudaOpenMP.cu.obj cudaOpenMP.cu
1>nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
1>Linking…
1>LINK : fatal error LNK1181: cannot open input file ‘.DebugcudaOpenMP.cu.obj’
1>Build log was saved at "file://d:MDTempProjectsCUDAprojectscudaOpenMPDebugBuildLog.htm"
1>cudaOpenMP – 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
(this is copy & paste from VS Output window)
and the error in VS Error Window:
Error 1 fatal error LNK1181: cannot open input file ‘.DebugcudaOpenMP.cu.obj’ cudaOpenMP cudaOpenMP
The error enlisted in VS Error window is connected with linker (it is unable to find input file) so the real problem lies somewhere else: at the compile time. I have copied the command line that invokes nVidia’s compiler (because no other compiler is aware of all the extension nVidia created for the purpose of creating CUDA). The command line was:
"C:Program FilesnVidiaCUDAbinnvcc.exe" -arch sm_10 -ccbin "C:Program FilesMicrosoft Visual Studio 9.0VCbin" -Xcompiler "/EHsc /W3 /nologo /Od /Zi /MTd " -IC:Program FilesnVidiaCUDAinclude -I../../common/inc -maxrregcount=32 –compile -o DebugcudaOpenMP.cu.obj cudaOpenMP.cu
Do you see the problem? Well, I didn’t see what’s wrong at the first sight too ;) Anyway, to cut it short: the problem lies in the path where nVidia CUDA SDK is installed. I have chosen to install it in “Program FilesnVidia” and not in the root directory (this is the default location – as far as I can remember). The thing is that Program Files without quotes is treated… yup, you guessed ;) everyone familiar with the way command lines arguments are being passed to programs knows that space IS a delimiter. OK. What is the solution? Very, very simple, you need to change a bit the “CUDA Build Rule”, and to change it, you need to do the following:
-
Open your VS and open any project / solution from nVidia CUDA samples
-
Right-click on project (not on solution) and click on “Custom Build Rules”, you should see a dialog:
-
Choose “Cuda Build Rule v2.1.0” and click on “Modify Rule File…” button, another window will pop-up:
-
Click on “Cuda Build Rule” and then on “Modify Build Rule…”
-
And finally this is the window you need to make changes in. The “Include” property (highlighted) need to be modified (simply: put [value] into quotes, so the switch for Include will look like: –I”[value]”. Now your project should compile without any errors or warnings (I assume that you’re compiling one of the nVidia CUDA samples).
-
Remember that you may have to add (register) .cu files in VS environment, but it is clearly described in readme.txt located in /doc/syntax_highlighting in your CUDA SDK directory.
The same kind of problem you may have after installing Python and some python IDEs that modify environment and add PYTHONPATH. If you install Python in “Program Files” the same thing happens. The solution is to edit your PYTHONPATH variable and change it, instead of “Program Files” you may type “Progra~1” (check what is yours “Program Files” directory 8+3 name using “dir /X” command).
Hope it helps. Happy coding!
Tags: CUDA, Custom Build Rules, PYTHONPATH