title: How to make CUDA 8 work on Visual Studio 2015 update 3 with CMake?
body: <p>I am having trouble even to compile the simplest code for CUDA 8 and Visual Studio 2015 update 3.</p>
  
  <p>CUDASample.cuh</p>
  
  <pre><code>class CUDASample {
   public:
    CUDASample();
    ~CUDASample();
  };
  </code></pre>
  
  <p>CUDASample.cu</p>
  
  <pre><code>#include "CUDASample.cuh"
  
  CUDASample::CUDASample() {
  }
  
  CUDASample::~CUDASample(){
  }
  </code></pre>
  
  <p>I am getting compilation errors like </p>
  
  <pre><code>1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(63): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(64): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(76): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(98): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(118): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(125): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(126): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(137): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(144): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(161): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(170): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(171): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(180): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(188): error : unknown attribute "guard"
  1&gt;C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt_malloc.h(189): error : unknown attribute "guard"
  </code></pre>
  
  <p>I am pretty sure it's a CUDA problem because if I change the source file extension to "cpp" and header extension to "h" everything works as usual. How can I solve this?</p>
  
  <p>EDIT:</p>
  
  <p>The commandline shown in properties -> Linker -> Command Line is</p>
  
  <pre><code>/OUT:"C:\Users\David\Desktop\sample\build\bin\Release\cudasample.dll" /MANIFEST /NXCOMPAT /PDB:"C:/Users/David/Desktop/sample/build/bin/Release/cudasample.pdb" /DYNAMICBASE "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\lib\x64\cudart_static.lib" /IMPLIB:"C:/Users/David/Desktop/sample/build/lib/Release/cudasample.lib" /DLL /MACHINE:X64 /INCREMENTAL:NO /PGD:"C:\Users\David\Desktop\sample\build\bin\Release\cudasample.pgd" /SUBSYSTEM:CONSOLE /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"cudasample.dir\Release\cudasample.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 
  </code></pre>
  
  <p>EDIT: </p>
  
  <p>As Robert mentioned, since I am able to compile the cuda samples successfully, the problem might be related to cmake configuration. Below is the CMakeLists I used which work for me when compiling on Visual Studio 2013 + CUDA 7.5.</p>
  
  <pre><code>project(cudasample)
  
  set(PROJECT_SRCS
  ${PROJECT_SOURCE_DIR}/src/CUDASample.cu
  )
  
  set(PROJECT_INCS
  ${PROJECT_SOURCE_DIR}/include/CUDASample.cuh
  )
  
  include_directories(${PROJECT_SOURCE_DIR}/include)
  
  find_package( CUDA REQUIRED )
  list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_52,code=sm_52;")
  list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_50,code=sm_50;")
  list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_35,code=sm_35;")
  list(APPEND CUDA_NVCC_FLAGS "-gencode arch=compute_30,code=sm_30;")
  if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
    set(CUDA_PROPAGATE_HOST_FLAGS OFF)
    list(APPEND CUDA_NVCC_FLAGS "-std=c++11;")
  endif()
  
  cuda_add_library(${PROJECT_NAME} SHARED ${PROJECT_SRCS} ${PROJECT_INCS})
  </code></pre>
  
  <p>What could be wrong?</p>