Error C1083 Cannot open include file: 'corecrt.h': No such file or directory (CUDA 10, VS 2017)

I am having problems compiling a CUDA project with more than one .cu file. I am using Windows 10, Microsoft Visual Studio 2017. The error is:
Error C1083 Cannot open include file: ‘corecrt.h’: No such file or directory

If I have just one .cu file, search.cu, which contains some code, there is no problem. Adding a second cu file, posneval.cu, causes the error. I’ve tried posneval.cu either empty, or just containing

#include “cuda.h”
#include “cuda_runtime.h”
global void kernelxxx() {
}

The full error message is below. Note that it is trying to compile search.cu, which is fine on its own. Changing the Generate Relocatable Code option does not help.

Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: ‘corecrt.h’: No such file or directory Sn99 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\include\crtdefs.h 10
Error MSB3721 The command ““C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\nvcc.exe” -gencode=arch=compute_35,code="sm_35,compute_35" --use-local-env -ccbin “C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64” -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /Fdx64\Debug\vc141.pdb /FS /Zi /RTC1 /MDd " -o x64\Debug\search.cu.obj “C:\Users\GRJ\AAA\Programming\Tinsmith\cppSource\Sn99\search.cu”” exited with code 2. Sn99 C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations\CUDA 10.0.targets 712

A successful build looks like this:

1>------ Rebuild All started: Project: Sn99, Configuration: Debug x64 ------
1>
1>C:\Users\GRJ\AAA\Programming\Tinsmith\VSprojects\Tinsmith\Sn99>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\nvcc.exe” -ccbin “C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64” -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler “/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -o x64\Debug\search.cu.obj “C:\Users\GRJ\AAA\Programming\Tinsmith\cppSource\Sn99\search.cu” -clean
1>search.cu
1>Compiling CUDA source file …....\cppSource\Sn99\search.cu…
1>
1>C:\Users\GRJ\AAA\Programming\Tinsmith\VSprojects\Tinsmith\Sn99>“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\bin\nvcc.exe” -gencode=arch=compute_35,code="sm_35,compute_35" --use-local-env -ccbin “C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\HostX86\x64” -x cu -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include” -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Fdx64\Debug\vc141.pdb /FS /Zi /RTC1 /MDd " -o x64\Debug\search.cu.obj “C:\Users\GRJ\AAA\Programming\Tinsmith\cppSource\Sn99\search.cu”
1>search.cu
1>Sn99main.cpp
1>utils.cpp
1>wrapalloc.cpp
1>wrapcuda.cpp
1>Generating Code…
1> Creating library C:\Users\GRJ\AAA\Programming\Tinsmith\VSprojects\Tinsmith\x64\Debug\Sn99.lib and object C:\Users\GRJ\AAA\Programming\Tinsmith\VSprojects\Tinsmith\x64\Debug\Sn99.exp
1>Sn99.vcxproj → C:\Users\GRJ\AAA\Programming\Tinsmith\VSprojects\Tinsmith\x64\Debug\Sn99.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

This is a bit of a puzzler. I looked at my installation which is 14.16.27023 and I found that file does not exist in it.

I did a bit more digging and found it is referenced in host_config.h of the CUDA API. I then found that it is only included if CUDACC is defined. None of my projects or the samples I have tried have that defined so they all compile just fine. This means somewhere you have that macro defined and it causing this problem.

Thanks for taking a look, ryork. I haven’t used CUDACC, and the docs say it is defined ‘when compiling’. I no longer think the problem has much, if anything, to do with CUDA, because…

The problem went away when I deleted lots of VS-generated files: everything in .vs, and everything in every x64 folder.