Cannot Compile Optix SDK Samples, "Cannot open source file"

Following the INSTALL-WIN.txt instructions, I am unable to build any SDK Samples on Windows 10 using Visual Studio 2022.
Here is the build log that appears when I attempt to build optixTriangle:

4>------ Build started: Project: sutil_7_sdk, Configuration: Debug x64 ------
4>Building NVCC optixir file lib/ptx/Debug/sutil_generated_camera.cu.optixir
4>camera.cu
4>Program
4>c1xx : fatal error C1083: Cannot open source file: 'ΓÇ£-IC:/Program': No such file or directory
4>NVIDIA
4>c1xx : fatal error C1083: Cannot open source file: 'Files/NVIDIA': No such file or directory
4>GPU
4>c1xx : fatal error C1083: Cannot open source file: 'GPU': No such file or directory
4>Computing
4>c1xx : fatal error C1083: Cannot open source file: 'Computing': No such file or directory
4>includeâ??
4>c1xx : fatal error C1083: Cannot open source file: 'Toolkit/CUDA/v11.8/bin/../includeΓÇ¥': No such file or directory
4>Program
4>c1xx : fatal error C1083: Cannot open source file: 'ΓÇ£-IC:/Program': No such file or directory
4>NVIDIA
4>c1xx : fatal error C1083: Cannot open source file: 'Files/NVIDIA': No such file or directory
4>GPU
4>c1xx : fatal error C1083: Cannot open source file: 'GPU': No such file or directory
4>Computing
4>c1xx : fatal error C1083: Cannot open source file: 'Computing': No such file or directory
4>cudartâ??
4>c1xx : fatal error C1083: Cannot open source file: 'Toolkit/CUDA/v11.8/bin/../include/cudartΓÇ¥': No such file or directory
4>Program
4>c1xx : fatal error C1083: Cannot open source file: 'ΓÇ£-IC:/Program': No such file or directory
4>Files
4>c1xx : fatal error C1083: Cannot open source file: 'Files': No such file or directory
4>Microsoft
4>c1xx : fatal error C1083: Cannot open source file: '(x86)/Microsoft': No such file or directory
4>Visual
4>c1xx : fatal error C1083: Cannot open source file: 'Visual': No such file or directory
4>includeâ??
4>c1xx : fatal error C1083: Cannot open source file: 'Studio/2022/VC/includeΓÇ¥': No such file or directory

It appears that file path strings are being split by spaces, causing a single valid path to be split into several invalid paths. Also strange characters appear before C:/Program Files. Any idea what could be happening?

I am unable to build any SDK Samples on Windows 10 using Visual Studio Code 2022.

Do you really mean Visual Studio Code or Microsoft Visual Studio 2022?
(I have never used Visual Studio Code to build OptiX programs.)

When really using Visual Studio Code, what exactly is the c1xx compiler tool chain used inside the error messages?

Which OptiX SDK version are you using?

Which CMake version did you use to configure and build the solutions?
Please try 3.27 (or newer). Those might throw some deprecation warning with older constructs used inside the OptiX SDK example framework but work on my systems. I’m currently running CMake 3.27.8 without issues.

The error messages look as if there is an issue with filenames in general.
What is is your OS’ local language setting?

The error messages indicate that the compiler tries to open files at
C:/Program Files/NVIDIA/GPU Computing/include
and
C:/Program Files (x86)/Microsoft Visual Studio/2022/VC/include
That are files from the CUDA Toolkit 11.8 default installation folder and from the MSVS 2022 32-bit version.

In CMake did you configure and generate the solution for Visual Studio 17 2022 and selected x64 as platform? (x86 32 bit won’t work!)

Other than that, the CMake scripts which generate the NVCC command lines, which happens with the CUDA_WRAP_SRCS macro inside the OptiX SDK example application framework have not shown issues with spaces inside the include directories. These should normally be all enclosed by quotation marks.

Your error output on system is garbled even before the first space, so that seems to be something else. I cannot tell where these come from.

Maybe provide the complete CMake output from the configure and generate steps on a clean build.
That would show which compiler is used and if there are any other problems when building the solution.

Do you really mean Visual Studio Code or Microsoft Visual Studio 2022?

Yes, I meant Microsoft Visual Studio 2022. That was a typo. It is fixed now.

When really using Visual Studio Code, what exactly is the c1xx compiler tool chain used inside the error messages?

When I type Get-Command cl in the VS Developer Powershell, it tells me that my cl.exe is located in
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\HostX86\x86\cl.exe

From the cmake-gui configure stage, we also have (full output is below):

Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped

Which OptiX SDK version are you using?

Optix 8.0.0

Which CMake version did you use to configure and build the solutions?

CMake 3.27.1

The error messages look as if there is an issue with filenames in general.
What is is your OS’ local language setting?

English (United States)

In CMake did you configure and generate the solution for Visual Studio 17 2022 and selected x64 as platform? (x86 32 bit won’t work!)

Yes.

Maybe provide the complete CMake output from the configure and generate steps on a clean build.

Here is the configure output:

Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19045.
The C compiler identification is MSVC 19.36.32537.0
The CXX compiler identification is MSVC 19.36.32537.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.36.32532/bin/Hostx64/x64/cl.exe - skipped
Detecting CXX compile features
Detecting CXX compile features - done
CMake Deprecation Warning at CMakeLists.txt:94 (cmake_policy):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.



Performing Test OPTIX_CXX_ACCEPTS_NO_CPP
Performing Test OPTIX_CXX_ACCEPTS_NO_CPP - Failed
Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.8 (found suitable version "11.8", minimum required is "5.0") 
Unsetting values associated with OptiX code generation
sutil OPTIXIR
ptx_files = C:/ProgramData/NVIDIA Corporation/OptiX SDK 8.0.0/SDK/build/lib/ptx/$(Configuration)/sutil_generated_camera.cu.optixir;C:/ProgramData/NVIDIA Corporation/OptiX SDK 8.0.0/SDK/build/lib/ptx/$(Configuration)/sutil_generated_geometry.cu.optixir;C:/ProgramData/NVIDIA Corporation/OptiX SDK 8.0.0/SDK/build/lib/ptx/$(Configuration)/sutil_generated_shading.cu.optixir;C:/ProgramData/NVIDIA Corporation/OptiX SDK 8.0.0/SDK/build/lib/ptx/$(Configuration)/sutil_generated_sphere.cu.optixir;C:/ProgramData/NVIDIA Corporation/OptiX SDK 8.0.0/SDK/build/lib/ptx/$(Configuration)/sutil_generated_whitted.cu.optixir
Found OpenGL: opengl32   
CMake Deprecation Warning at support/GLFW/CMakeLists.txt:5 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


Performing Test CMAKE_HAVE_LIBC_PTHREAD
Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
Looking for pthread_create in pthreads
Looking for pthread_create in pthreads - not found
Looking for pthread_create in pthread
Looking for pthread_create in pthread - not found
Found Threads: TRUE  
Could NOT find Vulkan (missing: VULKAN_LIBRARY VULKAN_INCLUDE_DIR) 
Using Win32 for window creation
Configuring done (5.5s)

Here is the generating output:

Generating done (0.7s)

What I think is happening on your system is that the quotation marks aren’t the correct ASCII codes.
If you check the printed characters before and after the path names with spaces, then the begin is always ΓÇ£ and the end is always ΓÇ¥.

The ASCII quotation mark is hexadecimal 0x1c, decimal 34, octal 042. In unicode that is (U+0022).
Could those be some unicode smart quotes instead of the ASCII 7-bit one from the keyboard "?

Did you touch any of the OptiX SDK CMakeLists.txt or *.cmake files?

CMake itself should support that https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#encoding but I doubt that this is the right thing when building a custom build rule for NVCC.

Even if you use English (United States) as language and territory settings, something might be different with the coded character set for the locale on your system.

I cannot reproduce this on my machine (English (United States), German keyboard) and don’t know how to correct that inside your WIndows settings.

Your CMake output looks very similar to my environment.
I’m using CMake 3.27.8 and that finds a slightly newer Windows SDK version 10.0.22621.0 on my system and I’m running Microsoft Visual Studio 2022 Professional and the compiler reports version MSVC 19.39.33523.0 which is also newer than yours.
Make sure the PATH environment variable points to the correct Windows SDK and CUDA Toolkit directories.

I’m running CUDA 12.2 but I also used 11.8 before without issues.
Everything else, except for local paths, is identical to your CMake output.

If there aren’t any other language settings affecting the problem, you could try updating the CMake version, the Windows SDK, check if there are updates for your MSVS version, and maybe also update the CUDA Toolkit 12.2. (Do not install the display driver components inside the CUDA toolkit! Instead install the newest display driver available to your GPU and OS when needed afterwards.)

Did you touch any of the OptiX SDK CMakeLists.txt or *.cmake files?

No. To be sure I reinstalled the OptiX SDK, trying versions 8.0.0 and 7.6.0. The same issue happens.

If there aren’t any other language settings affecting the problem, you could try updating the CMake version, the Windows SDK, check if there are updates for your MSVS version, and maybe also update the CUDA Toolkit 12.2. (Do not install the display driver components inside the CUDA toolkit! Instead install the newest display driver available to your GPU and OS when needed afterwards.)

I have tried updating CMake. My Visual Studio installer does not provide a newer version of the Windows 10 SDK to install. I have updated MSVS. I have tried with CUDE Toolkit 12.3. The same issue still happens.

I really can’t say why this is happening on your machine.
It could still be the older Visual Studio Community edition or the older Windows SDK.

The most similar error I could find is this but that doesn’t have the incorrect characters, it only chokes on the spaces:
https://stackoverflow.com/questions/66116251/error-c1083-how-do-i-fix-my-broken-visual-studio-compiler

Maybe provide the *.vcxproj file of the failing sutil build.

Some other web sites blamed the Windows SDK.
I never used the Visual Studio installer to install Windows SDKs.
The Windows SDK comes with its own installer:
https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/

Do other CMake projects work on your system?

You could try if you can get my OptiX examples to work. github link here:
https://forums.developer.nvidia.com/t/optix-advanced-samples-on-github/48410/4
I’m only using the OptiX SDK headers in a different application framework, so neither the OptiX SDK’s FindCUDA.cmake nor any other of its scripts or helpers.

Sidenote: CMake deprecated its own FindCUDA.cmake in version 3.10 and has finally hidden it in version 3.27!
https://cmake.org/cmake/help/latest/module/FindCUDA.html
It has been replaced with FindCUDAToolkit.cmake, respectively CMake’s native LANGUAGE CUDA feature.
Latter requires a separate CMake “Object Library” project to isolate the OptiX device code translation to PTX or OptiX-IR from native CUDA objects.
Described here: https://forums.developer.nvidia.com/t/why-am-i-getting-optix-dir-notfound/279085/4