Compiling from command line

I’m trying to compile a simple HelloCuda from command line, cause am not willing to install the 4 GB MS VS … though i have the microsoft cl.exe compiler.

Documentation really doesn’t help much, just relying on VS for windows !!

I need someone to give me an exact syntax for compiling and linking 3 files A.cu B.cu and C.cu from the command line.

currently using win7 64 bit … but 32 bit would do … just need the exact line that actually works.

Thats really serious cause am doing my thesis using CUDA and i cant get the simplest thing to compile

Thanks.

I don’t have an exact answer, but something like this is just the beginning:

[font=“Courier New”][indent]nvcc foo.cu -I"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include" -O3 [/indent][/font]

If you ever do install VS, then you can go to Visual Studio>Project>Properties>CUDA Build Rule (or whatever it’s called in your setup) and then look at the “Command Line” value.

That should provide you a rather robust starting point for command line compilation of your project outside of VS.

You can probably significantly trim down what VS emits. Looking at the output of “[font=“Courier New”]nvcc --help[/font]” is also helpful in understanding what’s happening.

Here’s what my command line looks like (via VS):

[font=“Courier New”][indent]“C:\CUDA\bin64\nvcc.exe” --keep --opencc-options -LIST:source=on --machine 64 -arch sm_11 -ccbin “c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin” -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT " -I"C:\CUDA\include” -I"C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK/C/common/inc" -I"C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK\shared\inc" -maxrregcount=32 --ptxas-options=-v --compile -o “build\x64\Release\XXX.cu.obj” “c:\PATH\TO\YOUR\PROJECT\XXX.cu” [/indent][/font]

That was really helpful, but this command line doesn’t specify the libs location … so i guess it doesn’t link the exe it just creates an obj file

Is there anyway you could also copy the linking command (which is my main problem btw :D)

Thanks

/OUT:"x64\Release\GNavigator.exe" /INCREMENTAL:NO /NOLOGO /LIBPATH:"C:\CUDA\lib" /LIBPATH:"C:\Program Files (x86)\NVIDIA Corporation\NVIDIA CUDA SDK\common\lib" /MANIFEST /MANIFESTFILE:"x64\Release\GNavigator.exe.intermediate.manifest" /NODEFAULTLIB:"nafxcw.lib" /DEBUG /PDB:"x64\Release\GNavigator.pdb" /SUBSYSTEM:WINDOWS /OPT:REF /OPT:ICF /LTCG /MACHINE:X64 /ERRORREPORT:PROMPT cudart.lib cuda.lib nvcuvid64.lib cutil64.lib

I usually put the cudart.dll (and any other needed dlls) in c:\windows\system32

Hope that helps

eyal

Which compiler is that … the nvcc or the cl … I guess its the cl.exe

Thanks :-) now i can create a make file.

I just have another question, what if the file I’m compiling is a cpp or cc, would I still nvcc to compile or should i use the cl.exe ??

You could make things much simpler on yourself and use CMake to generate the make files for you. It handles all these details.

A script to generate the makefile can be as simple as:

find_package(CUDA)

cuda_add_executable(my_exec source1.cu source2.cu source2.cpp source4.cpp)

Too much errors when i tried that, I only want to know the command line for linking, maybe if the CMake works for you … could you generate a MSYS make file and post it here

Thanks

Maybe I’ll do that next time I’m sitting at a windows machine (could be a few days).

But if all you really want to know is how to link object files into an exe on the command line in windows, there are probably better sources of information online than the CUDA forums. There is nothing CUDA specific about that operation.

nvcc -c file.cu -o file.obj

(possibly with all the other paths discussed previously) produces a standard object file that can be linked by a standard linker with along with all the other obj files. I’ve never done this by hand on windows so I cannot help further than my suggestion to use cmake, which is what I always use for projects larger than one file.

If it is just one .cu file, all you need is “nvcc -o test.exe test.cu” run in the visual studio command prompt. If that works for you, you could always add the --dryrun option to nvcc and see how it is linking the resulting object files.