Skip to content

Fix nvcc/glibc feature macro compatibility in CMake builds#403

Open
lahiri-phdworks wants to merge 1 commit intoNVIDIA:masterfrom
lahiri-phdworks:master
Open

Fix nvcc/glibc feature macro compatibility in CMake builds#403
lahiri-phdworks wants to merge 1 commit intoNVIDIA:masterfrom
lahiri-phdworks:master

Conversation

@lahiri-phdworks
Copy link

Build related issues.

Faced issues when building the cuda toolkit version 13.1 on Ubuntu operating system. Details from uname are below.

uname -a

Linux ----- 6.17.0-14-generic #14-Ubuntu SMP PREEMPT_DYNAMIC Fri Jan  9 17:01:16 UTC 2026 x86_64 GNU/Linux

CMake Errors.

The following cmake error was encountered.

CMake Error at /usr/share/cmake-3.31/Modules/CMakeDetermineCompilerId.cmake:865 (message): Compiling the CUDA compiler identification source file "CMakeCUDACompilerId.cu" failed. Compiler: /usr/local/cuda-13/bin/nvcc Build flags: Id flags: --keep;--keep-dir;tmp -v The output was: 2 #$ _NVVM_BRANCH_=nvvm #$ _SPACE_= #$ _CUDART_=cudart #$ _HERE_=/usr/local/cuda-13/bin #$ _THERE_=/usr/local/cuda-13/bin #$ _TARGET_SIZE_= #$ _TARGET_DIR_= #$ _TARGET_DIR_=targets/x86_64-linux #$ TOP=/usr/local/cuda-13/bin/.. #$ CICC_PATH=/usr/local/cuda-13/bin/../nvvm/bin #$ NVVMIR_LIBRARY_DIR=/usr/local/cuda-13/bin/../nvvm/libdevice #$ LD_LIBRARY_PATH=/usr/local/cuda-13/bin/../lib::/usr/local/cuda-13/lib64 #$ PATH=/usr/local/cuda-13/bin/../nvvm/bin:/usr/local/cuda-13/bin:/home/clustere502/.opam/default/bin:/home/clustere502/.opencode/bin:/home/clustere502/.nvm/versions/node/v25.6.0/bin:/home/clustere502/bin:/home/clustere502/.local/bin:/usr/local/bin:/home/clustere502/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/local/cuda-13/bin:/home/clustere502/.fzf/bin #$ INCLUDES="-I/usr/local/cuda-13/bin/../targets/x86_64-linux/include" #$ SYSTEM_INCLUDES="-isystem" "/usr/local/cuda-13/bin/../targets/x86_64-linux/include/cccl" #$ LIBRARIES= "-L/usr/local/cuda-13/bin/../targets/x86_64-linux/lib/stubs" "-L/usr/local/cuda-13/bin/../targets/x86_64-linux/lib" #$ CUDAFE_FLAGS= #$ PTXAS_FLAGS= #$ rm tmp/a_dlink.reg.c #$ gcc -D__CUDA_ARCH_LIST__=750 -E -x c++ -D__CUDACC__ -D__NVCC__ "-I/usr/local/cuda-13/bin/../targets/x86_64-linux/include" "-isystem" "/usr/local/cuda-13/bin/../targets/x86_64-linux/include/cccl" -D__CUDACC_VER_MAJOR__=13 -D__CUDACC_VER_MINOR__=1 -D__CUDACC_VER_BUILD__=115 -D__CUDA_API_VER_MAJOR__=13 -D__CUDA_API_VER_MINOR__=1 -D__NVCC_DIAG_PRAGMA_SUPPORT__=1 -D__CUDACC_DEVICE_ATOMIC_BUILTINS__=1 -include "cuda_runtime.h" -m64 "CMakeCUDACompilerId.cu" -o "tmp/CMakeCUDACompilerId.cpp4.ii" #$ cudafe++ --c++17 --static-host-stub --device-hidden-visibility --gnu_version=150200 --display_error_number --orig_src_file_name "CMakeCUDACompilerId.cu" --orig_src_path_name "/home/clustere502/cuda-samples/build/CMakeFiles/3.31.6/CompilerIdCUDA/CMakeCUDACompilerId.cu" --allow_managed --m64 --parse_templates --gen_c_file_name "tmp/CMakeCUDACompilerId.cudafe1.cpp" --stub_file_name "CMakeCUDACompilerId.cudafe1.stub.c" --gen_module_id_file --module_id_file_name "tmp/CMakeCUDACompilerId.module_id" "tmp/CMakeCUDACompilerId.cpp4.ii" /usr/include/x86_64-linux-gnu/bits/mathcalls.h(206): error: exception specification is incompatible with that of previous function "rsqrt" (declared at line 629 of /usr/local/cuda-13/bin/../targets/x86_64-linux/include/crt/math_functions.h) extern double rsqrt (double __x) noexcept (true); extern double __rsqrt (double __x) noexcept (true); ^ /usr/include/x86_64-linux-gnu/bits/mathcalls.h(206): error: exception specification is incompatible with that of previous function "rsqrtf" (declared at line 653 of /usr/local/cuda-13/bin/../targets/x86_64-linux/include/crt/math_functions.h) extern float rsqrtf (float __x) noexcept (true); extern float __rsqrtf (float __x) noexcept (true); ^ 2 errors detected in the compilation of "CMakeCUDACompilerId.cu". # --error 0x2 -- Call Stack (most recent call first): /usr/share/cmake-3.31/Modules/CMakeDetermineCompilerId.cmake:8 (CMAKE_DETERMINE_COMPILER_ID_BUILD) /usr/share/cmake-3.31/Modules/CMakeDetermineCompilerId.cmake:53 (__determine_compiler_id_test) /usr/share/cmake-3.31/Modules/CMakeDetermineCUDACompiler.cmake:131 (CMAKE_DETERMINE_COMPILER_ID) CMakeLists.txt:3 (project) -- Configuring incomplete, errors occurred!

The fix has been documented and implemented by changing the CMakeLists.txt files.

What’s actually failing is this: glibc’s <mathcalls.h> now declares rsqrt/rsqrtf, and CUDA 13.1’s header crt/math_functions.h also declares them, but with a different exception spec. When both are visible in the same compilation unit, we get the “exception specification incompatible” error.

Fix

Added the following.

if(NOT CMAKE_CUDA_FLAGS_INIT MATCHES "(^| )-U_GNU_SOURCE( |$)")
    string(APPEND CMAKE_CUDA_FLAGS_INIT " -U_GNU_SOURCE")
endif()
if(NOT CMAKE_CUDA_FLAGS_INIT MATCHES "(^| )-D_DEFAULT_SOURCE( |$)")
    string(APPEND CMAKE_CUDA_FLAGS_INIT " -D_DEFAULT_SOURCE")
endif()


set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Wno-deprecated-gpu-targets -U_GNU_SOURCE -D_DEFAULT_SOURCE")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -include ${CMAKE_SOURCE_DIR}/cmake/pthread_clock_compat.h")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments