Q: How to compile simple programs with Nvidia Optix Prime

What is the command to compile simple Optix programs such as optixhello.cpp? It comes with a cmake example files, but when I try to compile, it complains

CMake Error at CMakeLists.txt:33 (OPTIX_add_sample_executable):
Unknown CMake command "OPTIX_add_sample_executable".
-- Configuring incomplete, errors occurred!
See also "/opt/NVIDIA-OptiX-SDK-4.0.1-linux64/SDK/optixHello/CMakeFiles/CMakeOutput.log".

The OPTIX_add_sample_executable() call is about the only thing in CMakeLists.txt.

I’d prefer not to have to learn how to debug cmake because I can not use cmake in my project. I just want to get simple Optix Prime examples working. What is the command to compile optixhello.cpp? Or, better yet, is there a document that explains how to compile Optix examples?

Looks like you’re not creating a cmake build directory in the right place. Please read the INSTALL-LINUX.txt file that comes with the SDK and follow the instructions there, then post back if that doesn’t work for you.

Thank you. Yes, I eventually figured that out.

However, what is the correct way to compile Optix Prime programs from the Linux command-line? I want to incorporate Optix Prime into my project and I need to know what libraries to include. So far, I’ve come up with this:

COMPILE:

/usr/bin/c++ -fPIC -msse -msse2 -msse3 -mfpmath=sse -O3 -DNDEBUG -g3 -funroll-loops -I/opt/NVIDIA-OptiX-SDK-4.0.1-linux64/include -I/opt/NVIDIA-OptiX-SDK-4.0.1-linux64/SDK/sutil -I/opt/NVIDIA-OptiX-SDK-4.0.1-linux64/SDK -I/opt/NVIDIA-OptiX-SDK-4.0.1-linux64/include/optixu -I/usr/local/cuda/include -o mine.o -c mine.cpp

LINK:

/usr/bin/c++ -fPIC -msse -msse2 -msse3 -mfpmath=sse -O3 -DNDEBUG -g3 -funroll-loops mine.o -o mine -rdynamic /opt/NVIDIA-OptiX-SDK-4.0.1-linux64/lib64/liboptix_prime.so /opt/NVIDIA-OptiX-SDK-4.0.1-linux64/SDK/lib/libsutil_sdk.so /opt/NVIDIA-OptiX-SDK-4.0.1-linux64/lib64/liboptix.so -lm /opt/NVIDIA-OptiX-SDK-4.0.1-linux64/lib64/liboptixu.so /usr/local/cuda/lib64/libcudart_static.a -lpthread -lrt -ldl -lglut -lXmu -lXi -lGLU -lGL -lSM -lICE -lX11 -lXext -Wl,-rpath,/opt/NVIDIA-OptiX-SDK-4.0.1-linux64/SDK/lib:/opt/NVIDIA-OptiX-SDK-4.0.1-linux64/lib64

What should that be and where is this documented?

If you already have a standalone app that builds with a Makefile and you’re adding OptiX Prime (not regular OptiX) from scratch, then the steps are simpler:

  • compile: add “-I/opt/NVIDIA-OptiX-SDK-4.0.1-linux64/include” for the header include path
  • #include <optix_prime/optix_prime.h> (or <optix_prime/optix_primepp.h> for the C++ api)
  • link: add “-L /opt/NVIDIA-OptiX-SDK-4.0.1-linux64/lib64” and “-loptix_prime”.

The liboptix_prime library has no external dependencies, so you shouldn’t need to include or link anything else. The SDK samples all link to libsutil, a utility library, and other things like GLUT. You can omit all that in a standalone sample.

For regular OptiX (not Prime) the steps are similar, using liboptix instead of liboptix_prime, but you will also need to generate PTX for your shaders, using nvcc. See section 5 of the OptiX Programming Guide pdf for details.

How to compile simple programs with Optix Prime in windows?

Please read the OptiX SDK 5.0.1\SDK\INSTALL-WIN.txt document.
That explains how to build the OptiX SDK examples yourself under Windows.

Hello,

Actually if you build the generated solution from cmake (at least on my machine: Win10, cmake: 3.9.12, msvc14) there are some linking errors in the prime* projects.
That’s because the cu.obj files are never generated when building the prime projects. This happens due to the fact that the Build Event (that compiles the *cu.obj.cmake and generates the *cu.obj files is nested as a Custom Build Tool in the .cu file’s properties).
If you copy the Command Line commands and paste them as a Pre-Build Event in each prime
project’s properties, everything works fine. At least for me.

I hope this helps anyone having trouble to build the prime* projects in the generated solution.

Cheers,
Antonis