Problems building the various examples

I am 100% sure this is due to my lack of experience with c++, but whenever I try to build any of the samples (For example currently trying with GitHub - NVIDIA/OptiX_Apps: Advanced Samples for the NVIDIA OptiX 7 Ray Tracing SDK) I keep running into the same problem: Optix functions (like optixIgnoreIntersection) and types (CUdeviceptr) in the .cu files can’t be found.

I have Optix 7-7.2 and CUDA 10.1, 10.2. and 11.1 installed, all in their default directories. Driver is 456.71

What had me puzzled in CMake was the CUDA_SDK_ROOT_DIR not being found. Taken from someone else on the interwebs I set that to C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1/lib/x64 and tried building again, no change.

Any ideas what I am doing wrong here?

Normally if you follow the BuildingWindows section of the OptiX_Apps README.md by the letter, it should just build out of the box.

What is your host compiler version and CMake version?

Since 456.71 is a Windows driver version, I assume you’re running Windows 10 64-bit and use Visual Studio 2017 or 2019.

The CUDA_SDK_ROOT_DIR is not required for the build to work.
It’s the CUDA_TOOLKIT_ROOT_DIR, CUDA_TOOLKIT_INCLUDE, CUDA_NVCC_EXECUTABLE, CUDA_HOST_COMPILER, CUDA_CUDA_LIBRARY and CUDA_CUDART_LIBRARY CMake variables which are important.

  1. Start the CMake GUI and set the Where is the source code to your local <path>/OptiX_Apps repository folder.
  2. In Where to build the binaries pick some new folder inside that like <path>/OptiX_Apps/msvs2019
  3. Select File → Delete Cache
  4. Press Configure.
  5. In the CMake dialog select you Visual Studio version and, important, the x64 platform or nothing will work! (That host compiler must be the same with which you have built the 3rdparty libraries!)
  6. Provide the resulting CMake output.

Check all output for the correct folder locations. There should be no need to set anything manually if CMake’s FindCUDA.cmake works correctly:
It should say something like this:
Found CUDA: C:/sdk/CUDA/v11.1 (found suitable version "11.1", minimum required is "10.0")

If that is not the case, check your environment variables.

Open a command prompt and issue the command set c. That will list all CUDA environment variables.
The important one is CUDA_PATH. That points to the CUDA toolkit installation you’re currently using.

Still in the command prompt, issue the command set p. That will print the PATH environment variable among others.
Check if the CUDA toolkit bin directory of the version in your CUDA_PATH is part of the PATH variable.

Thanks a lot!

In CMake I have the CUDA_HOST_COMPILER, SDK_ROOT (which is not found), and TOOLKIT_ROOT, which is set to the correct directory (Program Files/NVidia GPU Computing Toolkit/CUDA/v11.1)

Looking at the output, there is one thing. It says: Found Optix7: and then points to the v10.1 CUDA includes. No idea if that is a problem or how to fix it

As for the rest, setting the paths, build env (debug/x64) I am doing exactly that and the cpp sources don’t seem to have an issue.

Here is CMake output, followed by the env vars

Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.

The C compiler identification is MSVC 19.27.29112.0

The CXX compiler identification is MSVC 19.27.29112.0

Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe

Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe -- works

Detecting C compiler ABI info

Detecting C compiler ABI info - done

Detecting C compile features

Detecting C compile features - done

Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe

Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe -- works

Detecting CXX compiler ABI info

Detecting CXX compiler ABI info - done

Detecting CXX compile features

Detecting CXX compile features - done

LOCAL_3RDPARTY = C:/Optix7/OptiX_Apps/3rdparty

CMAKE_MODULE_PATH = C:/Optix7/OptiX_Apps/3rdparty/CMake

Found OptiX72: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

Found OptiX71: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

Found OptiX7: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

PROJECT_NAME = intro_runtime

Found OpenGL: opengl32

Found GLFW: C:/Optix7/OptiX_Apps/3rdparty/glfw/include

Found GLEW: C:/Optix7/OptiX_Apps/3rdparty/glew/include

Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1 (found suitable version "11.1", minimum required is "10.0")

Found DevIL_1_8_0: C:/Optix7/OptiX_Apps/3rdparty/devil_1_8_0/include

PROJECT_NAME = intro_driver

PROJECT_NAME = intro_denoiser

PROJECT_NAME = intro_motion_blur

PROJECT_NAME = rtigo3

Found ASSIMP: C:/Optix7/OptiX_Apps/3rdparty/assimp/lib/assimp-vc142-mt.lib

PROJECT_NAME = nvlink_shared

Configuring done

The relevant set c output:

CUDA_PATH=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
CUDA_PATH_V10_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1
CUDA_PATH_V10_2=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2
CUDA_PATH_V11_1=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1
CUDA_PATH_V8_0=C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0

In regards to CUDA the path contains this:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\libnvvp

I tried adding the v11.1 path here and restarted VS, but that didn’t work.
Cleaned the CMake cache as well and after the Path change re-build in CMake

This is the CMake output after

Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.

The C compiler identification is MSVC 19.27.29112.0

The CXX compiler identification is MSVC 19.27.29112.0

Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe

Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe -- works

Detecting C compiler ABI info

Detecting C compiler ABI info - done

Detecting C compile features

Detecting C compile features - done

Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe

Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe -- works

Detecting CXX compiler ABI info

Detecting CXX compiler ABI info - done

Detecting CXX compile features

Detecting CXX compile features - done

LOCAL_3RDPARTY = C:/Optix7/OptiX_Apps/3rdparty

CMAKE_MODULE_PATH = C:/Optix7/OptiX_Apps/3rdparty/CMake

Found OptiX72: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

Found OptiX71: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

Found OptiX7: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

PROJECT_NAME = intro_runtime

Found OpenGL: opengl32

Found GLFW: C:/Optix7/OptiX_Apps/3rdparty/glfw/include

Found GLEW: C:/Optix7/OptiX_Apps/3rdparty/glew/include

Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1 (found suitable version "11.1", minimum required is "10.0")

Found DevIL_1_8_0: C:/Optix7/OptiX_Apps/3rdparty/devil_1_8_0/include

PROJECT_NAME = intro_driver

PROJECT_NAME = intro_denoiser

PROJECT_NAME = intro_motion_blur

PROJECT_NAME = rtigo3

Found ASSIMP: C:/Optix7/OptiX_Apps/3rdparty/assimp/lib/assimp-vc142-mt.lib

PROJECT_NAME = nvlink_shared

Configuring done
Found OptiX72: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include
Found OptiX71: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include
Found OptiX7: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include

But how?! That is just wrong and the root cause for your issues.
That output needs to print your OptiX SDK installation folders.

The FindOptiX*.cmake inside 3rdparty/CMake are completely agnostic to CUDA.

Please check if you have made any changes to the FindOptiX*.cmake scripts or if you have any other FindOptiX*.cmake files inside the CMAKE_MODULE_PATH CMake variable.

Or simply cleanly clone the repository again.
Make sure there are no changes before you attempt to build the 3rdparty libraries and apps.

I assume the order in which you installed the CUDA toolkits is in increasing version number. The CUDA 11.1 bin and libnvvp should have been the first in the PATH environment variable, before the older CUDA toolkits’ folders.
If it was not present inside your PATH variable that could be due to an incorrect installation.
(Shouldn’t really matter for the OptiX 7 apps as long as the CUDA_TOOLKIT_ROOT_DIR , CUDA_TOOLKIT_INCLUDE , CUDA_NVCC_EXECUTABLE , CUDA_HOST_COMPILER , CUDA_CUDA_LIBRARY and CUDA_CUDART_LIBRARY all point to the right version.)

This was the nth attempt at this :) I even redownloaded it, and unzipped it to a new directory, not touching anything. So no changes to any files. And again, this happens with other samples etc. as well (the Optix course for example)

Oooooh… it is possible I installed CUDA 10.1 after 11.1. This could be because what I found as sources for Optix targets different CUDA/Optix versions.

I re-installed and I still get:

Found OptiX72: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include  
Found OptiX71: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include  
Found OptiX7: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include  

For the CUDA paths, do you know where I can find the default settings? Google fails me here.

I have not the slightest idea how this could happen at all.
If this is not only happening with my examples but also the completely different ones from Ingo, something is really screwed up with your system.

Your CUDA environment variables look correct. Those are the defaults.
(I’m installing SDKs to a different folder, because Program Files is protected.)

Where are your OptiX SDK 7.0.0, 7.1.0, 7.2.0 installed?

Have you set any OPTIX_PATH, OPTIX7_PATH, OPTIX71_PATH, OPTIX72_PATH environment variables?
If yes, do they point to the correct OptiX SDK installation folders?

Maybe add message("OPTIX7_PATH = " "${OPTIX7_PATH}") after the set(OPTIX7_PATH $ENV{OPTIX7_PATH}).
Similar for 71 and 72 in all FindOptiX*.cmake versions.
What is printed inside the CMake GUI output when uncommenting all message calls inside my FindOptiX*.cmake scripts?

If that still doesn’t reveal any error, I would be tempted to uninstall all CUDA toolkits, clean the PATH variable of all remaining CUDA toolkit traces, and remove any other CUDA related environment variable, and then install only the toolkits really needed again in ascending version order, if something like this happens.
I normally use the CUDA Toolkit Web Installer and disable everything related to the Display Drivers.
Some CUDA installers have wiped the NVIDIA Control Panel (right click on dektop).
If that happens uninstall the display driver, reboot, reinstall the 456.71 via the Custom installation and check the Clean Installation box.

Thanks, I give this a shot! I just hope I don’t have to re-install windows.

I didn’t manually set any of the OPTIX_PATH

I uncommented those messages:

Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.
The C compiler identification is MSVC 19.27.29112.0
The CXX compiler identification is MSVC 19.27.29112.0
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe -- works
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Detecting C compile features
Detecting C compile features - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe -- works
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Detecting CXX compile features
Detecting CXX compile features - done
LOCAL_3RDPARTY = C:/Optix7/OptiX_Apps/3rdparty
CMAKE_MODULE_PATH = C:/Optix7/OptiX_Apps/3rdparty/CMake
OPTIX72_INCLUDE_DIR = C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include
Found OptiX72: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include
OptiX72_FOUND = TRUE
OPTIX71_INCLUDE_DIR = C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include
Found OptiX71: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include
OptiX71_FOUND = TRUE
OPTIX7_INCLUDE_DIR = C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include
Found OptiX7: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/include
OptiX7_FOUND = TRUE
PROJECT_NAME = intro_runtime
Found OpenGL: opengl32
Found GLFW: C:/Optix7/OptiX_Apps/3rdparty/glfw/include
Found GLEW: C:/Optix7/OptiX_Apps/3rdparty/glew/include
Found CUDA: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.1 (found suitable version "11.1", minimum required is "10.0")
Found DevIL_1_8_0: C:/Optix7/OptiX_Apps/3rdparty/devil_1_8_0/include
PROJECT_NAME = intro_driver
PROJECT_NAME = intro_denoiser
PROJECT_NAME = intro_motion_blur
PROJECT_NAME = rtigo3
Found ASSIMP: C:/Optix7/OptiX_Apps/3rdparty/assimp/lib/assimp-vc142-mt.lib
PROJECT_NAME = nvlink_shared
Configuring done

I’ll take a stab then at uninstalling all the CUDA Toolkits. I usually use the local installer and custom as well. Will make sure to disable the driver bits (didn’t do that before)

Which CMake version are you using? I’m using 3.17.3

But where are your OptiX SDKs installed?

Are they not in the folder the FindOptiX scripts are looking for under Windows?
set(OPTIX72_PATH “C:/ProgramData/NVIDIA Corporation/OptiX SDK 7.2.0”)

If not, what happens if you set the OPTIX72_PATH environment variable to your OptiX SDK 7.2.0 installation folder?

I mean if none of the SDKs is found, the OPTIX*_INCLUDE_DIR should be empty and OptiX*_FOUND should be false.

We’re making head way!

I uninstalled all the CUDA SDKs and reinstalled 10.2 and 11.1 in that order. CMake now finds Optix in their proper directories.

As for the Optix directories, just like the rest I installed it in the default locations, so C:\ProgramData\NVIDIA Corporation\OptiX SDK 7.2.0 etc

It builds most of the solution. Except nvlink_shared and rtigo3 have a problem. They can’t open assimp

Error	LNK1104	cannot open file '..\..\..\3rdparty\assimp\lib\assimp-vc142-mt.lib'	nvlink_shared	C:\Optix7\OptiX_Apps\build\apps\nvlink_shared\LINK	1	

After following the instructions I ended up with assimp-vc141-mt.lib

That would indicate a Visual C difference between 14.1 and 14.2, which means you’ve built the 3rdparty libraries including ASSIMP inside an x64 Native Tools Command Prompt for VS 2017 but are generating the solution for MSVS 2019 according to your MSVC 19.27.29112.0 version number.

Please use the x64 Native Tools Command Prompt for VS 2019 to build the 3rdparty libraries.

I ran the 3rdparty.cmd again, double checking that it was with the VS 19 command prompt (was 100% sure it did it the last time as well), same result, sadly :/

Please open that x64 Native Tools Command Prompt for VS 2019 command prompt again and issue the command cl.exe

What version is that reporting?

If that is not the same as you had in your CMake output

The C compiler identification is MSVC 19.27.29112.0
The CXX compiler identification is MSVC 19.27.29112.0

then you’re not running the same Visual C toolkits.

The versioning is a little convoluted in later MSVS versions:
19.10-19.19 = VS 15.0 (v141 toolset) = MSVS 2017
19.20-19.29 = VS 16.0 (v142 toolset) = MSVS 2019

Means if your cl.exe is not reporting a version in the range 19.20 - 19.29 then you’re not running the required VC 14.2 toolkits matching your MSVS 2019 solution.

For example on my system
MSVS 2017 cl.exe reports Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27043 for x64
MSVS 2019 cl.exe reports Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29112 for x64

It’s possible to run older VC toolkits with newer MSVS versions. I’m not doing that.
https://devblogs.microsoft.com/cppblog/side-by-side-minor-version-msvc-toolsets-in-visual-studio-2019/

Note that I do not have this output from your configuration in my CMake at all:
Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.

I get

Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29112 for x64

As for the Win SDK, which version should I have installed/uninstalled?

Ok, that’s the correct MSVS 2019 version then.

Then you would need to figure out why the 3rdparty build script for ASSIMIP is not using the correct VC toolkits yourself.
If you comment out this line at the very end of the 3rdparty.cmake script, it’ll keep all intermediate build files in that temp folder:
execute_process(COMMAND ${CMAKE_COMMAND} -E remove_directory "${CMAKE_CURRENT_SOURCE_DIR}/temp")

You could also just build that library yourself using CMake and the MSVS 2019 IDE.

If either is not generating an assimp-vc142-mt.lib/.dll, then you could check inside the *.vcproj what tools it used.

For the Windows SDK, I don’t have any installed. I also don’t know if this has anything to do with your build issues.
This is just completely guessing on my part because none of that has ever been happening before.
Sorry, I’m running out of ideas.

I’ll try that

No worries. I know I’ve been a difficult customer today :) I really appreciate your help!

Thanks a lot, worst case this should have helped with the other solutions I had problems with. And there was some learning :)

Did you notice that there was this output in your CMake configuration before?
Found ASSIMP: C:/Optix7/OptiX_Apps/3rdparty/assimp/lib/assimp-vc142-mt.lib

And now you can only build assimp-vc141-mt.lib? That doesn’t make sense. Try to find out what you did differently.

Either you’re not restarting all apps after changing any environment variable or something else about your software setup is really bogus.

You still haven’t answered which CMake version you use. Maybe your CMake version is just bugged?
I’m using CMake 3.17.3 64-bit.

Oh, strange. Now I haven’t noticed that about the assimp versions.

I am running CMake 3.14.1. x64, just updated now to the most recent 3.19 x64

The good news is that the Optix course works now! So I am working with that for the moment and see how far I get.

The only other thing I can think of is that the 3rdparty.cmake is not correctly detecting the version of the cl.exe. but the regular expression here
https://github.com/NVIDIA/OptiX_Apps/blob/master/3rdparty.cmake#L36
should be working for your output
Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29112 for x64

Please watch the output of the two messages after that in line 39 and 40.
If that doesn’t match what the version detection does here:
https://github.com/NVIDIA/OptiX_Apps/blob/master/3rdparty.cmake#L62
then that’s one problem which is easy to solve: Just hardcode the cl_version or comment out the MSVS cases you don’t need.

Ok, commenting out the other MSVS options did it!

Having had a quick look this also covers a lot of my use cases. Thanks again! :)

This shouldn’t have been necessary in the first place.
I would be interested to see what the message log of the 3rdparty.cmake was before it starts building the libraries.

If that failed to determine the correct version, there is either a problem with which compiler gets reported in your command prompt (but we’ve compared that above already) or the regular expression in my script isn’t finding the major and minor numbers as intended.
(I know that it doesn’t support all languages. Spanish MSVS versions for example will not report the word “Version”.)

(Mind that latest stable CMake release is 3.18.4. The 3.19.0 version is a release candidate.)