# Issue with CMAKE\_CUDA\_COMPILER\_EXTERNAL\_TOOLCHAIN

**URL:** https://discourse.cmake.org/t/issue-with-cmake-cuda-compiler-external-toolchain/5286
**Category:** Usage
**Created:** [March 24, 2022, 6:50pm UTC](https://discourse.cmake.org/t/issue-with-cmake-cuda-compiler-external-toolchain/5286 "2022-03-24T18:50:04Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![mafanasiev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@mafanasiev](https://discourse.cmake.org/u/mafanasiev)
#### Post date: [March 24, 2022, 6:50pm UTC](https://discourse.cmake.org/t/issue-with-cmake-cuda-compiler-external-toolchain/5286/1 "2022-03-24T18:50:04Z")

</div>

Hello,

I believe there may be an issue setting an external compiler toolchain for CUDA. For me this is popping up when I am using Clang to compile CUDA. For instance, running `cmake` with a trivial `CMakeLists.txt` and a toolchain file like the following:

```auto
SET (CMAKE_SYSTEM_NAME Linux)
SET (CMAKE_SYSTEM_VERSION centos7)
SET (CMAKE_SYSTEM_PROCESSOR x86_64)

SET (TOOLCHAIN_ROOT "/opt/toolchains")
SET (TARGET_TRIPLE "x86_64-centos7-linux-gnu")
SET (TOOLCHAIN_DIR "${TOOLCHAIN_ROOT}/${TARGET_TRIPLE}")
SET (CMAKE_SYSROOT ${TOOLCHAIN_ROOT}/${TARGET_TRIPLE}/${TARGET_TRIPLE}/sysroot)

SET (CMAKE_C_COMPILER_TARGET ${TARGET_TRIPLE})
SET (CMAKE_CXX_COMPILER_TARGET ${TARGET_TRIPLE})
SET (CMAKE_CUDA_COMPILER_TARGET ${TARGET_TRIPLE})
SET (CMAKE_C_COMPILER_EXTERNAL_TOOLCHAIN ${TOOLCHAIN_ROOT}/${TARGET_TRIPLE})
SET (CMAKE_CXX_COMPILER_EXTERNAL_TOOLCHAIN ${TOOLCHAIN_ROOT}/${TARGET_TRIPLE})
SET (CMAKE_CUDA_COMPILER_EXTERNAL_TOOLCHAIN ${TOOLCHAIN_ROOT}/${TARGET_TRIPLE})

SET (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
SET (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

```

will fail with an error ending in the following:

```auto
  #include "..." search starts here:

  #include <...> search starts here:

   /opt/local/include
   /usr/lib/llvm-13/lib/clang/13.0.1/include/cuda_wrappers
   /usr/local/cuda/include
   /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9
   /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/x86_64-linux-gnu/c++/9
   /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/backward
   /usr/lib/llvm-13/lib/clang/13.0.1/include
   /opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot/usr/include

  End of search list.

   "/usr/bin/ld" --sysroot=/opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot/usr/lib/../lib64/crt1.o /opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot/usr/lib/../lib64/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtbegin.o -L/opt/local/lib -L/usr/bin/../lib/gcc/x86_64-linux-gnu/9 -L/opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot/lib/../lib64 -L/opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot/usr/lib/../lib64 -L/opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot/lib -L/opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot/usr/lib /tmp/CMakeCUDACompilerId-a635d5.o -lmpicxx -rpath /opt/local/lib --enable-new-dtags -lmpi -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-linux-gnu/9/crtend.o /opt/toolchains/x86_64-centos7-linux-gnu/x86_64-centos7-linux-gnu/sysroot/usr/lib/../lib64/crtn.o

  /usr/bin/ld: /usr/bin/../lib/gcc/x86_64-linux-gnu/9/libstdc++.so: undefined
  reference to `__cxa_thread_atexit_impl@GLIBC_2.18'

  clang: error: linker command failed with exit code 1 (use -v to see
  invocation)

```

When running clang manually as a cuda compiler, with an explicit pass of `--gcc-toolchain=TOOLCHAIN_DIR`, compilation proceeds without an issue. Looking at the compiler invocation, and the search paths above, it seems that `--gcc-toolchain` is not being set for Clang CUDA targets, unlike C and C++ targets, where `CMAKE_LANG_COMPILER_EXTERNAL_TOOLCHAIN` properly set the `--gcc-toolchain` flag.

Might there be an issue forwarding this option to clang when it is used as a CUDA compiler? Or perhaps I am doing something else wrong.

Thanks alot for any help!
