Cross compile OpenCV4 for Jetson Nano


I’m trying to cross compile OpenCV 4.3.0 with CUDA for Jetson Nano target. I already have OpenCV without CUDA cross compiled successfully, now having difficulty enabling CUDA support.

The problem I have is openCV cmake keeps giving me this error message, and I’m not sure which options to pass in: Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_INCLUDE_DIRS)

Here’s what I have installed on my host machine performing cross compilation:

  • cuda-toolkit-10-0 which gives me host nvcc and /usr/local/cuda-10.0/targets/x86_64-linux header files and libraries.
  • cuda-cross-aarch64-10-0 which gives me /usr/local/cuda-10.0/targets/aarch64-linux header files and libraries.

This is the relevant options that I pass to OpenCV cmake:

cmake \
-DCUDA_NVCC_EXECUTABLE=/usr/local/cuda-10.0/bin/nvcc \
-DCUDA_HOST_COMPILER=/toolchain/linaro/bin/aarch64-linux-gnu-gcc \
-DCUDA_INCLUDE_DIRS=/usr/local/cuda-10.0/targets/aarch64-linux/include \
-DCUDA_CUDART_LIBRARY=/usr/local/cuda-10.0/targets/aarch64-linux/lib/ \

When I add -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.0 option, I get this error message instead even though I have clearly provided CUDA_INCLUDE_DIRS and CUDA_CUDART_LIBRARY.
Could NOT find CUDA (missing: CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (found suitable version "10.0", minimum required is "6.5")

I have also applied FindCUDA.cmake from but still fails with the same error.

Any help is greatly appreciated.


Please file a topic over openCV forum. Thanks.

Solved it myself.

Turns out that cmake was using FindCUDA.cmake from my system rather than opencv4.3.0/cmake/FindCUDA.cmake.

Fixing cmake search path fixed the issue.

1 Like

@jasaw81 Could you explain how you used FindCUDA.cmake on your system and the complete cmake command?

Thank you very much.

Add the below line to the top of opencv4.3.0/cmake/OpenCVDetectCUDA.cmake. This adds opencv4.3.0/cmake directory into the search path.


If it fails, try swapping the order around so it finds the opencv4.3.0/cmake path before your system cmake path:


Thank you for your information. I solved the problem meanwhile by compiling it on the nano and generating .deb packages which I can reuse!

Cross compile seemed not worth the effort…

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") worked for me too, thanks!