Makefiles and nvcc


my application is compiled and linked with a makefile. Now I am integrating the CUDA library, so I want to handle the ‘nvcc’ compilation step with the same makefile system.

The problem is that if I use the Micros0ft ‘nmake’ tool, the nvcc compilation gives an error (I presume, because he is not able to initialize the HERE variable), but the same makefile does not give problems if processed by the GNU ‘make’ tool, which is very similar to nmake.

Here is a part of my makefile, which launches nvcc to do the compilation:


nvcc --verbose -deviceemu -c $< 

              -Xcompiler /EHsc,/W3,/Wp64,/O2,/Zi,/MD $(CH_INCLUDES) 

              -I$(CH_CUDA_SDK_INC) -I$(CH_CUDA_INC) -o "$*.obj"

This will give two outcomes, depending if it is processed by ‘nmake’ or the Gnu ‘make’ (mingw32-make for windows), despite both build tools expand the command in the same identical way!

Here 's what happens with nmake:

> nvcc -deviceemu -c lcp/ -Xcompiler /EHsc,/W3,/Wp64,/O2,/Zi,/MD 

     -I"C:\tasora\code\Argonne\CODE\ChronoEngine\source"  -I"c:\tasora\code\js/src"  




     -I"C:\Programmi\NVIDIA Corporation\NVIDIA CUDA SDK\common\inc" 


     -o "lcp/CHlcpIterativeCuda.obj"

>#$ _SPACE_= 


>#$ _HERE_=(null)

> Internal error

> NMAKE : fatal error U1077: 'c:\cuda\bin\nvcc.EXE' : return code '0xc0000005'

… and here’s what happens with the GNU make ‘mingw32-make’ :

> nvcc -deviceemu -c lcp/ ..etc.. [... same as above!!...]

>#$ _SPACE_=


>#$ _HERE_=c:\cuda\bin

>#$ _THERE_=c:\cuda\bin

>#$ TOP=c:\cuda\bin/..

>#$ PATH=c:\cuda\bin/../extools/bin; [....and many other paths here...]

>#$ INCLUDES="-Ic:\cuda\bin/../include" "-Ic:\cuda\bin/../include/cudart"

>#$ LIBRARIES=  "/LIBPATH:c:\cuda\bin/../lib" cudart.lib




>#$ VSINSTALLDIR=C:\Programmi\Microsoft Visual Studio 8\VC\BIN/../..

>#$ VCINSTALLDIR=C:\Programmi\Microsoft Visual Studio 8\VC\BIN/../..

>#$ C:\Programmi\Microsoft Visual Studio 8\VC\BIN/../../common7/Tools/vsvars32.bat


Does this depend on the way nmake launches commands?

Is there a way to avoid this? (I cannot rely on GNU make only - I must

support also nmake)

I tried playing a bit with the .profile file, but without success…


I have the same problem as well. exists with CUDA 2.0 as well!

If I invoke NVCC from command-line, it is all fine. However, if NMAKE does it – NVCC somehow fails with an internal error.

CAn some1 from NVIDIA throw some light here? Are we missing something basic here??

Best Regards.

For the moment, I fixed this problem in this way: I created a .bat script that launches the NVCC. Such script is called by Nmake without problems.
Of course this is a workaround, and I hope that Nvidia programmers can
explain this strange Nmake incompatibility.

By the way, along with the abovementioned nmake problem, also the
impossibility of using VC2008 with nvcc is limiting my development with
the gpu, so I hope that the new release of CUDA is around the corner…

Alessandro Tasora

…by the way, my .bat script (that wraps nvcc to avoid the problem of calling nvcc directly from nmake) is very simple:


REM NVCC compile script - 

REM This is a workaround, since nvcc cannot be called from

REM Microsoft 'nmake', so this script is called instead and

REM all goes fine.


echo NVCC executing...

nvcc %nvcc_par% 

echo ..NVCC done

So, the NMAKE can do something like the following to invoke nvcc using the wrapper (also passing few additional infos like compiler flags & inclused using the nvcc_par variable that I reserve for this)…


        SET nvcc_par= $(MY_NVCCFLAGS) -c $< $(MY_INCLUDES) -o "$*.obj"


Well, I hope that this ‘trick’ can be helpful to other people that experienced that weird incompatibility between nvcc and NMAKE.

Alessandro Tasora

Thank you Alex. The scripts look cool!


I just moved to the CMAKE-CUDA work done by Abe Stephens and it works like a charm using “nMake”.

All Abe does is to convert .CU files to .CPP files using the “-cuda” option of NVCC and uses the host compiler to do the rest.

This works from the command prompt without any problems!

Probably you could give this a try.

I’ve seen similar errors with others programs when used inside a Makefile. The easiest solution is to redirect output of nvcc to file or nul. For example:
nvcc [options] > nul

something wrong with the way nmake passes along stdout handle
if you add 1>&2 (redirect stdout to stderr) all goes okay