First, optix_stubs.h
is just a convenience header which lifts the entry point function names of the dynamically loaded OptixFunctionTable
into the global namespace.
The g_optixFunctionTable
is not defined inside the optix_stubs.h
header itself. That only contains an extern declaration to that global variable: extern OptixFunctionTable g_optixFunctionTable;
The actual definition of that global variable is contained inside the header optix_function_table_definition.h
:
/// If the stubs in optix_stubs.h are used, then the function table needs to be defined in exactly
/// one translation unit. This can be achieved by including this header file in that translation
/// unit.
OptixFunctionTable g_optixFunctionTable;
and as the comment says, that optix_function_table_definition.h
must be included in exactly one translation unit (module, C++ file). The OptiX SDK examples show that.
The undefined symbol: g_optixFunctionTable
compiler error would mean there is an #include <optix_stubs.h>
header missing inside a translation unit which calls one of the global namespace versions of the OptiX API functions.
The undefined reference to g_optixFunctionTable
linker error instead would mean that the linker is not finding that global variable, which in turn means you’re missing the #include <optix_function_table_definition.h>
inside your static library code.
What exactly is the reason for putting a header-only API into a static library?
I’m not even using the optix_stubs.h
header in my own OptiX examples but just load the OptixFunctionTable into a class member variable.
https://github.com/NVIDIA/OptiX_Apps/blob/master/apps/rtigo10/src/Device.cpp#L550