General Crosscompiling NVCC

Hello there,

we have a Jetson Nano production module with a custom carrier board and yocto operating system with CUDA 10.0.
We want to cross compile code for the nano, which is no problem as long as we use g++ and othe GNU tools.
As soon as we want to specify cross compile variables for NVCC, untoward things happen.
Crosscompiling should be pretty simple.

  1. You have a compiler in host architecture that can crosscompile - our NVCC should be able to do it, as I read
  2. You need to know the target architecture
  3. You need to specify the target libraries and includes and specify them to the compiler
  4. You need to compile the code to objects
  5. You need to link the objects together

As we do not get it to work with CMake or autotools we wanted to keep it simple an try to start with compiling by hand.

So we tried something like this:
-v for verbose output
–sysroot for the specification of the root of the system where the compiler should search for includes and libraries
sysroot shoul make normal --library-path and --include-path unnecessary
–library-path=… for specifying the target libraries to use
–include-path=… for specifying the include directories of the target

Our try at compiling and linking in one:
nvcc -v --compiler-options=–sysroot={SDKTARGETSYSROOT} --library-path={SDKTARGETSYSROOT}/usr/local/cuda-10.0/lib --library-path={SDKTARGETSYSROOT}/usr/local/cuda-10.0/lib/stubs --library-path={SDKTARGETSYSROOT}/usr/lib --include-path=${SDKTARGETSYSROOT}/usr/include

where the SDKTARGETSYSROOT is an aarch64 folder
The host is x86_64
I have changed the long paths in the following output to host_cuda which describes the path to the cuda installation on for the host.

This does not work as visible here:
# _SPACE_= # CUDART=cudart
# _HERE_=host_cuda/bin # THERE=host_cuda/bin
# _TARGET_DIR_=targets/x86_64-linux # TOP=host_cuda/bin/…
# NVVMIR_LIBRARY_DIR=host_cuda/bin/../nvvm/libdevice # LD_LIBRARY_PATH=host_cuda/bin/…/lib:
# PATH= (many things, only cuda_host stuff) # INCLUDES="-Ihost_cuda/bin/…/targets/x86_64-linux/include"
# LIBRARIES= "-Lhost_cuda/bin/../targets/x86_64-linux/lib/stubs" "-Lhost_cuda/bin/../targets/x86_64-linux/lib" # CUDAFE_FLAGS=

Errors follow, because mostly the host includes are used, sometimes the target includes.

Specifying the target-directory was introduced in CUDA 10.2, so no possibilty to use this.

How do I specify the sysroot of the target and ignore host includes and libs?

All in all: How to cross compile with NVCC 10.0?