How can i solve the bug that "CMakeCUDACompilerId.cu" failed?

Hi, everyone!
I’m learning to write program in CUDA. However, the first time i ran the hello_world.cu with CMake , something went wrong… I 've searched on the internet, while still cannot find an effective solution. Moreover, when i complied a libtorch program in C++, i encountered the same problem.

cmake version 3.27.7, Cuda compilation tools, release 11.5, V11.5.50 and i ran the program on remote server via VSCode.
What should I do?
Many thanks!

CMake Error at /media/data3/xxxx/cmake/share/cmake-3.27/Modules/CMakeDetermineCompilerId.cmake:753 (message):
  Compiling the CUDA compiler identification source file
  "CMakeCUDACompilerId.cu" failed.

  Compiler: /usr/local/cuda-11.5/bin/nvcc

  Build flags:

  Id flags: --keep;--keep-dir;tmp -v



  The output was:

  1

  #$ _NVVM_BRANCH_=nvvm

  #$ _SPACE_=

  #$ _CUDART_=cudart

  #$ _HERE_=/usr/local/cuda-11.5/bin

  #$ _THERE_=/usr/local/cuda-11.5/bin

  #$ _TARGET_SIZE_=

  #$ _TARGET_DIR_=

  #$ _TARGET_DIR_=targets/x86_64-linux

  #$ TOP=/usr/local/cuda-11.5/bin/..

  #$ NVVMIR_LIBRARY_DIR=/usr/local/cuda-11.5/bin/../nvvm/libdevice

  #$ LD_LIBRARY_PATH=/usr/local/cuda-11.5/bin/../lib:/usr/local/cuda/lib64:

  #$
  PATH=/usr/local/cuda-11.5/bin/../nvvm/bin:/usr/local/cuda-11.5/bin:/media/data3/xxxx/cmake/bin:/media/data3/xxxx/miniconda3/bin:/media/data3/xxxx/miniconda3/condabin:/usr/local/cuda/bin:/home/xxxx/.vscode-server/bin/f1b07bd25dfad64b0167beb15359ae573aecd2cc/bin/remote-cli:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin


  #$ INCLUDES="-I/usr/local/cuda-11.5/bin/../targets/x86_64-linux/include"

  #$ LIBRARIES=
  "-L/usr/local/cuda-11.5/bin/../targets/x86_64-linux/lib/stubs"
  "-L/usr/local/cuda-11.5/bin/../targets/x86_64-linux/lib"

  #$ CUDAFE_FLAGS=

  #$ PTXAS_FLAGS=

  #$ rm tmp/a_dlink.reg.c

  #$ gcc -D__CUDA_ARCH__=520 -D__CUDA_ARCH_LIST__=520 -E -x c++
  -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__
  "-I/usr/local/cuda-11.5/bin/../targets/x86_64-linux/include"
  -D__CUDACC_VER_MAJOR__=11 -D__CUDACC_VER_MINOR__=5
  -D__CUDACC_VER_BUILD__=50 -D__CUDA_API_VER_MAJOR__=11
  -D__CUDA_API_VER_MINOR__=5 -D__NVCC_DIAG_PRAGMA_SUPPORT__=1 -include
  "cuda_runtime.h" -m64 "CMakeCUDACompilerId.cu" -o
  "tmp/CMakeCUDACompilerId.cpp1.ii"

  #$ cicc --c++17 --gnu_version=110300 --display_error_number
  --orig_src_file_name "CMakeCUDACompilerId.cu" --orig_src_path_name
  "/media/data3/xxxx/model_deployment/cuda/CMakeFiles/3.27.7/CompilerIdCUDA/CMakeCUDACompilerId.cu"
  --allow_managed -arch compute_52 -m64 --no-version-ident -ftz=0 -prec_div=1
  -prec_sqrt=1 -fmad=1 --include_file_name "CMakeCUDACompilerId.fatbin.c"
  -tused --gen_module_id_file --module_id_file_name
  "tmp/CMakeCUDACompilerId.module_id" --gen_c_file_name
  "tmp/CMakeCUDACompilerId.cudafe1.c" --stub_file_name
  "tmp/CMakeCUDACompilerId.cudafe1.stub.c" --gen_device_file_name
  "tmp/CMakeCUDACompilerId.cudafe1.gpu" "tmp/CMakeCUDACompilerId.cpp1.ii" -o
  "tmp/CMakeCUDACompilerId.ptx"

  /usr/include/stdio.h(189): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(201): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(223): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(260): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(285): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(294): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(303): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(309): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(315): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdio.h(830): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdlib.h(566): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdlib.h(570): error: attribute "__malloc__" does not take
  arguments



  /usr/include/stdlib.h(799): error: attribute "__malloc__" does not take
  arguments



  13 errors detected in the compilation of "CMakeCUDACompilerId.cu".

  # --error 0x1 --





Call Stack (most recent call first):
  /media/data3/xxxx/cmake/share/cmake-3.27/Modules/CMakeDetermineCompilerId.cmake:8 (CMAKE_DETERMINE_COMPILER_ID_BUILD)
  /media/data3/xxxx/cmake/share/cmake-3.27/Modules/CMakeDetermineCompilerId.cmake:53 (__determine_compiler_id_test)
  /media/data3/xxxx/cmake/share/cmake-3.27/Modules/CMakeDetermineCUDACompiler.cmake:307 (CMAKE_DETERMINE_COMPILER_ID)
  CMakeLists.txt:4 (enable_language)

try a newer CUDA version than 11.5 see here

thanks for your help!! i reinstall the cuda-11.7 under user dir instead of root dir. however, i encounter the same problem. i discover that there is something wrong with the system variants. For example, $NVVMIR_LIBRARY_DIR only includes path of the old version cuda, and $PATH includes both the new and old version cuda. i am confused since i have updated the $PATH, $LD_LIBRARY_PATH in ~/.bashrc file. i use grep command to search whether other files include path like ‘/usr/local/cuda-11.5/bin/…/lib’, while it doesn’t exist.

i guess the reason is that cmake cannot find the proper nvcc complier, so i use the -DCMAKE_CUDA_COMPILER property. it works but i still wonder how to solve the problem thoroughly.

eg, explicitly:
cmake . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CUDA_COMPILER=`which nvcc`