# CUDA aarch64 cross compile fails to validate nvcc

**URL:** https://discourse.cmake.org/t/cuda-aarch64-cross-compile-fails-to-validate-nvcc/593
**Category:** Code
**Tags:** os:linux
**Created:** [February 6, 2020, 4:18pm UTC](https://discourse.cmake.org/t/cuda-aarch64-cross-compile-fails-to-validate-nvcc/593 "2020-02-06T16:18:52Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DKB](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dkb/32/126_2.png) [@DKB](https://discourse.cmake.org/u/DKB)
#### Post date: [February 6, 2020, 4:18pm UTC](https://discourse.cmake.org/t/cuda-aarch64-cross-compile-fails-to-validate-nvcc/593/1 "2020-02-06T16:18:52Z")

</div>

I’m attempting to use a toolchain file to cross-compile from Linux x86\_64 to aarch64.

```auto
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)

set(CMAKE_TOOLS_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-linux-gnu- CACHE STRING "")

set(CMAKE_C_COMPILER ${CMAKE_TOOLS_PREFIX}gcc)
set(CMAKE_C_COMPILER_TARGET ${CMAKE_SYSTEM_PROCESSOR})
set(CMAKE_C_COMPILER_AR ${CMAKE_TOOLS_PREFIX}ar)

set(CMAKE_CXX_COMPILER ${CMAKE_TOOLS_PREFIX}g++)
set(CMAKE_CXX_COMPILER_TARGET ${CMAKE_SYSTEM_PROCESSOR})
set(CMAKE_CXX_COMPILER_AR ${CMAKE_TOOLS_PREFIX}ar)

set(CMAKE_AR ${CMAKE_TOOLS_PREFIX}ar)

set(CMAKE_CUDA_COMPILER ${CUDA_HOST_TOOLKIT_ROOT_DIR}/bin/nvcc)
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER} CACHE INTERNAL "")

```

However, I’m running into major issues.

1. With the above, the linker fails during the CUDA compiler detection.

```auto
Linking CUDA executable cmTC_89859                                                                                                                                                                                                       
    /home/utils/cmake-3.12.4/bin/cmake -E cmake_link_script CMakeFiles/cmTC_89859.dir/link.txt --verbose=1                                                                                                                                   
    "" CMakeFiles/cmTC_89859.dir/main.cu.o CMakeFiles/cmTC_89859.dir/cmake_device_link.o -o cmTC_89859                                                                                                                          
    Error running link command: No such file or directory

```

I’ve tried to set up the linker command directly using the following code, but the necessary libraries are not applied such as `-lcudart` so the link still fails.

```auto
set(CMAKE_LINKER ${CMAKE_CXX_COMPILER} CACHE STRING "")
set(CMAKE_CUDA_HOST_LINK_LAUNCHER ${CMAKE_LINKER} CACHE STRING "")

```

```auto
Linking CUDA executable cmTC_3e539
    /home/utils/cmake-3.12.4/bin/cmake -E cmake_link_script CMakeFiles/cmTC_3e539.dir/link.txt --verbose=1
    aarch64-linux-gnu-g++ CMakeFiles/cmTC_3e539.dir/main.cu.o CMakeFiles/cmTC_3e539.dir/cmake_device_link.o -o cmTC_3e539
    CMakeFiles/cmTC_3e539.dir/main.cu.o: In function `__cudaUnregisterBinaryUtil()':
    tmpxft_00005923_00000000-5_main.cudafe1.cpp:(.text+0x70): undefined reference to `__cudaUnregisterFatBinary'
    CMakeFiles/cmTC_3e539.dir/main.cu.o: In function `__nv_init_managed_rt_with_module(void**)':
    tmpxft_00005923_00000000-5_main.cudafe1.cpp:(.text+0x90): undefined reference to `__cudaInitModule'
    CMakeFiles/cmTC_3e539.dir/main.cu.o: In function ` __sti____ cudaRegisterAll()':
    tmpxft_00005923_00000000-5_main.cudafe1.cpp:(.text+0xe0): undefined reference to `__cudaRegisterFatBinary'
    tmpxft_00005923_00000000-5_main.cudafe1.cpp:(.text+0x120): undefined reference to `__cudaRegisterFatBinaryEnd'
    CMakeFiles/cmTC_3e539.dir/cmake_device_link.o: In function `__cudaUnregisterBinaryUtil':
    link.stub:(.text+0x14): undefined reference to `__cudaUnregisterFatBinary'
    collect2: error: ld returned 1 exit status

```

1. If I instead just force all the compilers to skip the checking, my compiles then fail because it seems my CMAKE\_CXX\_STANDARD and other related settings don’t get propagated to the compiler flags, so I get errors stating I need to apply -std=c++11. I’ve seen this can be an issue on Mac builds, but not for linux cross-complation.

Does CMake require you to specify all the CXX, CUDA, and linker flags manually if you do cross-compilation?

This is seen using CMake 3.12.4 and 3.13. I’m going to try a few others as well.

Thanks!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [February 16, 2020, 12:51am UTC](https://discourse.cmake.org/t/cuda-aarch64-cross-compile-fails-to-validate-nvcc/593/2 "2020-02-16T00:51:00Z")

</div>

@robert.maynard

---

<div class="post-metadata">

### Author: ![DKB](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dkb/32/126_2.png) [@DKB](https://discourse.cmake.org/u/DKB)
#### Post date: [April 22, 2020, 9:34pm UTC](https://discourse.cmake.org/t/cuda-aarch64-cross-compile-fails-to-validate-nvcc/593/3 "2020-04-22T21:34:21Z")

</div>

@robert.maynard, any tips on debugging the issues?
