cross compiler opencv application(with cuda),always failed in cmake

hi,
I want to cross compiler the opencv application on my pc,but always failed in cmake.I have copyed the /usr of xavier to my pc .Below is the CMakeLists.txt and erros about cmake.

CMakeLists.txt

# cmake needs this line
cmake_minimum_required(VERSION 2.8)

# Define project name
project(opencv_example_project)

set(CMAKE_SYSTEM_NAME Linux)

set(CMAKE_C_COMPILER /opt/gcc-linaro-6.4.1-2017.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-gcc)

set(CMAKE_CXX_COMPILER /opt/gcc-linaro-6.4.1-2017.08-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++)

set(CMAKE_FIND_ROOT_PATH /home/work/rootfs/ )

set(CMAKE_MODULE_PATH /home/work/rootfs/usr/share/cmake-3.10/Modules/)

set(CUDA_TOOLKIT_ROOT_DIR /home/work/rootfs/usr/local/cuda)
find_package(CUDA REQUIRED)
message(STATUS "    libraries: ${CUDA_LIBS}")

set(OpenCV_DIR /home/work/rootfs/home/nvidia/work/opencv-nocuda/opencv-3.4.0/release/)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()

# Declare the executable target built from your sources
add_executable(opencv_example example.cpp)

# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS})

cmake errors

$ cmake ..
-- The C compiler identification is GNU 7.4.0
-- The CXX compiler identification is GNU 7.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
/home/work/rootfs/usr/local/cuda/bin/nvcc: 1: /home/work/rootfs/usr/local/cuda/bin/nvcc: ELF��I@@Ȼ@8@@@@@@PP��@�@ee@@������C�C�: not found
/home/work/rootfs/usr/local/cuda/bin/nvcc: 2: /home/workrootfs/usr/local/cuda/bin/nvcc: Syntax error: "(" unexpected
CMake Error at /home/work/rootfs/usr/share/cmake-3.10/Modules/FindCUDA.cmake:746 (string):
  string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
  command.
Call Stack (most recent call first):
  CMakeLists.txt:28 (find_package)

CMake Error at /home/work/rootfs/usr/share/cmake-3.10/Modules/FindCUDA.cmake:747 (string):
  string sub-command REGEX, mode REPLACE needs at least 6 arguments total to
  command.
Call Stack (most recent call first):
  CMakeLists.txt:28 (find_package)

-- Found CUDA: /home/work/rootfs/usr/local/cuda (found version ".") 
--     libraries: 
CMake Error at /home/work/rootfs/home/nvidia/work/opencv-nocuda/opencv-3.4.0/release/OpenCVConfig.cmake:108 (message):
  OpenCV static library was compiled with CUDA 10.0 support.  Please, use the
  same version or rebuild OpenCV with CUDA .
Call Stack (most recent call first):
  CMakeLists.txt:42 (find_package)

-- Configuring incomplete, errors occurred!
See also "/home/work/cross-compiler/cam_c++11/example_cmake/build/CMakeFiles/CMakeOutput.log".

Do you have idea what cuda does cmake find here?

-- Found CUDA: /home/work/rootfs/usr/local/cuda (found version ".") 
--     libraries:

hi WayneWWW,
I do not know ,but /home/work/rootfs/usr/local/cuda path is the cuda 10.0.I do not know why can not identify the verison 10.0.And how to solve the problem of nvcc when we cross compiler the code.

$ ll /home/work/rootfs/usr/local
total 44
drwxrwxrwx 11 jason jason 4096 Sep  9 20:13 ./
drwxrwxrwx 12 jason jason 4096 Aug  5 03:23 ../
drwxrwxrwx  2 jason jason 4096 Aug  5 21:41 bin/
lrwxrwxrwx  1 jason jason    9 Aug  5 03:09 cuda -> cuda-10.0/
drwxrwxrwx 12 jason jason 4096 Aug  5 03:09 cuda-10.0/
drwxrwxrwx  2 jason jason 4096 Apr 26  2018 etc/
drwxrwxrwx  2 jason jason 4096 Apr 26  2018 games/
drwxrwxrwx  4 jason jason 4096 Aug  5 18:45 include/
drwxrwxrwx  5 jason jason 4096 Aug  5 18:45 lib/
lrwxrwxrwx  1 jason jason    9 Apr 26  2018 man -> share/man/
drwxrwxrwx  2 jason jason 4096 Apr 26  2018 sbin/
drwxrwxrwx  9 jason jason 4096 Sep  2 19:53 share/
drwxrwxrwx  2 jason jason 4096 Apr 26  2018 src/

I think you should refer to below link but not use the rootfs directly.

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#cross-platform

hi WayneWWW,
Thank you ! I will refer this link.Do anyone have tried to use the rootfs of xavier to cross compiler the cuda on pc?

Hi Jason_888,

I think the problem here is you are trying to run a aarch64 nvcc on your x86_64 host.

hi WayneWWW,
Yes ,I think so .But I do not know what is the effect of nvcc when execute the ind_package(CUDA REQUIRED) in cmake.And can I use any way to solved this problem?

Hi Jason_888,

I am also facing the issue that FindCUDA.cmake identifies CUDA version as “.”

Have you found a solution to this problem yet, because I could not make it work till now.

I am also compiling on x86_64 (Ubuntu 16.04) for Jetson Nano (production) aarch64, Ubuntu 18.04.

I use the default the rootfs from the Jetpack (4.1 rev. 2) and install CUDA (10.0) inside it using chroot.

Then I use a toolchain file, along with cmake for cross compiling with option

CUDA_TOOLKIT_ROOT=/usr/local/cuda

and inside this toolchain file, I set the CMAKE_FIND_ROOT_PATH to the path of the (modified) rootfs on host.

Do we have to have a cuda-cross-aarch64 to identify the correct CUDA (for aarch64) version while running on x86_64 host?

Hi,

For cross-compiling a CUDA program, please check this document for details:
https://devblogs.nvidia.com/cuda-jetson-nvidia-nsight-eclipse-edition/

Thanks.