Build problems with OptiX - optixu_math_namespace.h fminf, fmaxf, copysignf

System:
OS: OpenSuse 42.3
GPU: Quadro M5000M
Driver: 418.30
RAM: 32G
CPU: Intel® Core™ i7-6920HQ CPU @ 2.90GHz
OptiX: 6.0.0
CUDA: 10.0
NVCC Build Settings: -m64 --use_fast_math -arch=sm_30 -DNVCC

Hi!
Recently, I’ve been updating our build system and in the process, I rewrote the linking of OptiX into our project. I’m using custom build targets for OptiX -

add_library(OptiX::IncludeOnly INTERFACE IMPORTED)
    set_target_properties(OptiX::IncludeOnly PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES ${CUDA_TOOLKIT_INCLUDE}
    )

    add_library(OptiX::Sutil SHARED IMPORTED)
    set_target_properties(OptiX::Sutil PROPERTIES
        IMPORTED_LOCATION ${_IMPORT_PREFIX}/SDK-precompiled-samples/libsutil.so
        INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/SDK/sutil/
    )
    
    add_library(OptiX::SutilSDK SHARED IMPORTED)
    set_target_properties(OptiX::SutilSDK PROPERTIES
        IMPORTED_LOCATION ${_IMPORT_PREFIX}/SDK-precompiled-samples/libsutil_sdk.so
        INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/SDK/sutil/
    )

    add_library(OptiX::Cudnn SHARED IMPORTED)
    set_target_properties(OptiX::Cudnn PROPERTIES
        IMPORTED_LOCATION ${_IMPORT_PREFIX}/lib64/libcudnn.so
        INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/include
    )

    add_library(OptiX::Denoiser SHARED IMPORTED)
    set_target_properties(OptiX::Denoiser PROPERTIES
        IMPORTED_LOCATION ${_IMPORT_PREFIX}/lib64/liboptix_denoiser.so
        INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/include
    )

    add_library(OptiX::Prime SHARED IMPORTED)
    set_target_properties(OptiX::Prime PROPERTIES
        IMPORTED_LOCATION ${_IMPORT_PREFIX}/lib64/liboptix_prime.so
        INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/include
    )

    add_library(OptiX::Main SHARED IMPORTED)
    set_target_properties(OptiX::Main PROPERTIES
        IMPORTED_LOCATION ${_IMPORT_PREFIX}/lib64/liboptix.so
        INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/include
    )

    add_library(OptiX::OptixU SHARED IMPORTED)
    set_target_properties(OptiX::OptixU PROPERTIES
        IMPORTED_LOCATION ${_IMPORT_PREFIX}/lib64/liboptixu.so
        INTERFACE_INCLUDE_DIRECTORIES ${_IMPORT_PREFIX}/include
    )

Now I have the problem that fminf, fmaxf, copysignf are clashing with other math function on the OS.

In file included from /home/VIRES/ViresDependencies/OptiX/NVIDIA-OptiX-SDK-6.0.0-linux64/include/optix_world.h:70:0,
                 from /home/VIRES/VIG_cmake/VIG/VigFramework/inc/VigFramework/ShmLayoutOptiX.h:80,
                 from /home/VIRES/VIG_cmake/VIG/VigFramework/inc/VigFramework/RDBInterface.h:14,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/vigcar/src/VCarHDRRenderer.h:10,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/ViewerWidget.h:19,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/dialogs/DialogShowroom.h:16,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/dialogs/DialogShowroom.cpp:1:
/home/VIRES/ViresDependencies/OptiX/NVIDIA-OptiX-SDK-6.0.0-linux64/include/optixu/optixu_math_namespace.h: In function ‘float copysignf(float, float)’:
/home/VIRES/ViresDependencies/OptiX/NVIDIA-OptiX-SDK-6.0.0-linux64/include/optixu/optixu_math_namespace.h:183:63: error: declaration of ‘float copysignf(float, float)’ has a different exception specifier
 OPTIXU_INLINE float copysignf(const float dst, const float src)
In file included from /home/VIRES/ViresDependencies/OptiX/NVIDIA-OptiX-SDK-6.0.0-linux64/include/optix_world.h:70:0,
                 from /home/VIRES/VIG_cmake/VIG/VigFramework/inc/VigFramework/ShmLayoutOptiX.h:80,
                 from /home/VIRES/VIG_cmake/VIG/VigFramework/inc/VigFramework/RDBInterface.h:14,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/vigcar/src/VCarHDRRenderer.h:10,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/ViewerWidget.h:19,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/dialogs/DialogShowroom.h:16,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/dialogs/DialogShowroom.cpp:1:
/home/VIRES/ViresDependencies/OptiX/NVIDIA-OptiX-SDK-6.0.0-linux64/include/optixu/optixu_math_namespace.h: In function ‘float fmaxf(float, float)’:
/home/VIRES/ViresDependencies/OptiX/NVIDIA-OptiX-SDK-6.0.0-linux64/include/optixu/optixu_math_namespace.h:177:55: error: declaration of ‘float fmaxf(float, float)’ has a different exception specifier
 OPTIXU_INLINE float fmaxf(const float a, const float b)
                                                       ^
In file included from /usr/include/c++/4.8/cmath:44:0,
                 from /home/VIRES/ViresDependencies/OpenSceneGraph/OpenSceneGraph-3.6.3/include/osg/Math:17,
                 from /home/VIRES/ViresDependencies/OpenSceneGraph/OpenSceneGraph-3.6.3/include/osg/Vec2f:17,
                 from /home/VIRES/ViresDependencies/OpenSceneGraph/OpenSceneGraph-3.6.3/include/osg/Vec2d:17,
                 from /home/VIRES/ViresDependencies/OpenSceneGraph/OpenSceneGraph-3.6.3/include/osg/Vec3d:17,
                 from /home/VIRES/ViresDependencies/OpenSceneGraph/OpenSceneGraph-3.6.3/include/osg/Matrixd:18,
                 from /home/VIRES/ViresDependencies/OpenSceneGraph/OpenSceneGraph-3.6.3/include/osg/Matrix:18,
                 from /home/VIRES/ViresDependencies/OpenSceneGraph/OpenSceneGraph-3.6.3/include/osgGA/GUIEventAdapter:18,
                 from /home/VIRES/VIG_cmake/VIG/VigFramework/inc/VigFramework/VIGCommon.h:14,
                 from /home/VIRES/VIG_cmake/VIG/VigFramework/inc/VigFramework/IGComponent.h:6,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/Showroom.h:4,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/ShowroomController.h:4,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/dialogs/DialogShowroom.h:14,
                 from /home/VIRES/VIG_cmake/VIG/VigApplications/Showroom/src/dialogs/DialogShowroom.cpp:1:
/usr/include/bits/mathcalls.h:348:1: error: from previous declaration ‘float fmaxf(float, float) throw ()’
 __MATHCALLX (fmax,, (_Mdouble_ __x, _Mdouble_ __y), (__const__));

I could fix the problem by removing the 3 functions from optixu_math_namespace.h, but I’m seriously wondering if this is the right approach. I saw some other oprojects having the same issue - https://ignitionrobotics.org/api/rendering/0.1/index.html - but this does not look like a proper fix to me. It would be great to see a suggestion from the OptiX comunity and the NVIDIA guys :)

Thanks a lot!
Jakub

Yes, this is bad style and happened before, but to not break old programs there was only a check for a define added inside the optixu_math_namespace.h in line 3171 to workaround that issue:

#if !defined(RT_NO_GLOBAL_NAMESPACE_INJECTION)

Please try if defining RT_NO_GLOBAL_NAMESPACE_INJECTION removes these namespace clashes.

Unfortunately did not help - the error stayed the same. I tried most of the defines already. I’m curious why it’s not standard in “optix” namespace. Then it should never clash or am I missing something?

Ok fixed it for GCC 4.8.5 +

  • After changing from c++ 11 to 98, I saw a better error explanation since the fmaxf, fminf and copysignf were not defined in cmath.h - “#if __cplusplus >= 201103L)”
  • There I finally saw what exception is expected - “throw()”
  • Since it’s an equivalent to noexcept(true) and therefore means it’s not throwing at all, I suppose it’s safe to add ;)
OPTIXU_INLINE float fminf(const float a, const float b) throw ()
{
  return a < b ? a : b;
}

OPTIXU_INLINE float fmaxf(const float a, const float b) throw ()
{
  return a > b ? a : b;
}

// copy sign-bit from src value to dst value
OPTIXU_INLINE float copysignf(const float dst, const float src) throw ()
{
  union {
    float f;
    unsigned int i;
  } v1, v2, v3;
  v1.f = src;
  v2.f = dst;
  v3.i = (v2.i & 0x7fffffff) | (v1.i & 0x80000000);

  return v3.f;
}

After this change, everything compiles smoothly.
You might be interested in adding the throw() expression to the new OptiX version.

Hi,
I wanted to come back to this thread since I saw that OptiX 6.5 did not address this issue and did not add the missing “throw()” at the end of the math functions.

Since OptiX 7 does not have these headers inside the SDK, I think we can consider this thread closed. Still, it would be nice to hear an official outcome from Nvidia :)