Undefined symbol: g_optixFunctionTable during execution

I have built a static library containing optix. It builds using cmake without a problem. Now I am using this static library in another project. It is linked with target_link_libraries. This other project also builds using cmake without a problem.
But during execution I get the following error:

undefined symbol: g_optixFunctionTable

This problem might be related to Linking Optix7 with GCC, but as he had the problem during build and not during execution, I decided to create a new topic. I also have included optix_stubs.h in my static library.

I realized, that I also cannot build the unit tests of the static library, because I get the following error during build:

undefined reference to `g_optixFunctionTable'

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

Thank you for the detailed explanation! I had optix_function_table_definition.h included at the wrong position. It works now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.