Cmake cannot find CUDAToolkit

Hi, I’m working on cross compile but there are some questions
host computer: ubuntu18.04 (jetpack 4.6.2)
target device: Jetson AGX Xavier(jetpack 4.6.2)

before build my own code, I can successfully build example code from jetson_multimedia_api by mounting
the clone.img.raw from cloning target device.

I build code by CMakeLists.txt and Toolchain.cmake for cross compile
the configuration of Toolchain like below

/home/gw/jetson is where I mount clone.img.raw

set(CMAKE_SYSTEM_NAME Linux)

########### CROSS COMPILER GCC 9 ###############################
# which C and C++ compiler to use
set(CMAKE_C_COMPILER /home/gw/aarch64--glibc--stable-final/bin/aarch64-linux-gcc)
set(CMAKE_CXX_COMPILER /home/gw/aarch64--glibc--stable-final/bin/aarch64-linux-g++)
################################################################################


set(CMAKE_FIND_ROOT_PATH /home/gw/jetson
                                                        /home/gw/jetson/usr/local
                                                        /home/gw/jetson/usr/lib/aarch64-linux-gnu/cmake/opencv4
                                                        /home/gw/jetson/usr/lib/aarch64-linux-gnu)

set(CUDA_TOOLKIT_ROOT_DIR /home/gw/jetson/usr/local/cuda-10.2

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)

and the execute cmake toolchain.cmake …

the Error code is below

-- Unable to find cuda_runtime.h in "/usr/local/cuda/targets//include" for CUDAToolkit_INCLUDE_DIR.
-- Unable to find cublas_v2.h in either "" or "/usr/local/math_libs/include"
-- Unable to find cudart library.
CMake Error at /home/gw/cmake-3.24.3/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find CUDAToolkit (missing: CUDAToolkit_INCLUDE_DIR CUDA_CUDART)
  (found version "10.2.300")
Call Stack (most recent call first):
  /home/gw/cmake-3.24.3/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /home/gw/cmake-3.24.3/Modules/FindCUDAToolkit.cmake:818 (find_package_handle_standard_args)
  CMakeLists.txt:48 (find_package)

I am stuck in here, I could find cuda_runtime.h in
/usr/local/cuda-10.2/targets/aarch64-linux/include or
/usr/local/cuda-10.2/targets/x86_64-linux/include or
/home/gw/jetson/usr/local/cuda-10.2/targets/aarch64-linux/include
but cmake is unable to find it by find_package(CUDAToolkit REQUIRED)

Hi,

Based on the below document, please manually set the CUDAToolkit_ROOT path to see if it works.

https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html

$ cmake -DCUDAToolkit_ROOT=/some/path) ..

Thanks.

Hi, thanks for your reply
as you said, I specified the path to CUDAToolkit_ROOT=/home/gw/jetson/usr/local/cuda-10.2
but still can’t work

-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /home/gw/aarch64--glibc--stable-final/bin/aarch64-linux-gcc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/gw/aarch64--glibc--stable-final/bin/aarch64-linux-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Warning (dev) at CMakeLists.txt:18 (find_package):
  Policy CMP0074 is not set: find_package uses <PackageName>_ROOT variables.
  Run "cmake --help-policy CMP0074" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  CMake variable CUDAToolkit_ROOT is set to:

    /home/gw/jetson/usr/local/cuda-10.2

  For compatibility, CMake is ignoring the variable.
This warning is for project developers.  Use -Wno-dev to suppress it.

/lib/ld-linux-aarch64.so.1: No such file or directory
-- Unable to find cuda_runtime.h in "/home/gw/jetson/usr/local/cuda-10.2/targets//include" for CUDAToolkit_INCLUDE_DIR.
-- Unable to find cublas_v2.h in either "" or "/home/gw/jetson/usr/local/math_libs/include"
-- Unable to find cudart library.
CMake Error at /home/gw/cmake-3.24.3/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find CUDAToolkit (missing: CUDAToolkit_INCLUDE_DIR CUDA_CUDART)
Call Stack (most recent call first):
  /home/gw/cmake-3.24.3/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /home/gw/cmake-3.24.3/Modules/FindCUDAToolkit.cmake:818 (find_package_handle_standard_args)
  CMakeLists.txt:18 (find_package)


-- Configuring incomplete, errors occurred!

it seems the variable is ignored

Hi,

Could you double check the CUDA path?
In general, it should under /usr/local/cuda-10.2/.

Thanks.

user@user:/usr/local/cuda$ ls
bin doc EULA.txt extras include lib64 libnsight libnvvp nsightee_plugins nvml nvvm nvvmx samples Sanitizer share src targets tools version.json version.txt

or you mean cuda path shoud be set at ?

thanks, I can find cudatoolkit but still has warning by CMake

CMake Warning at /home/gw/cmake-3.24.3/Modules/FindCUDAToolkit.cmake:922 (message):
  Could not find librt library, needed by CUDA::cudart_static
Call Stack (most recent call first):
  CMakeLists.txt:22 (find_package)

then I print out the information about CUDAToolkit by CMake, the result like below

Found CUDAToolkit

-- CUDAToolkit_VERSION: 10.2.300
-- CUDAToolkit_VERSION_MAJOR: 10
-- CUDAToolkit_VERSION_MINOR: 2
-- CUDAToolkit_VERSION_PATCH: 300
-- CUDAToolkit_BIN_DIR: /home/gw/jetson/usr/local/cuda/bin
-- CUDAToolkit_INCLUDE_DIR: /home/gw/jetson/usr/local/cuda/targets/aarch64-linux/include
-- CUDAToolkit_LIBRARY_DIR: /home/gw/jetson/usr/local/cuda/targets/aarch64-linux/lib
-- CUDAToolkit_NVCC_EXECUTABLE /home/gw/jetson/usr/local/cuda/bin/nvcc

Hi,

In general, the CUDA library should be installed under /usr/loca/cuda/.
But it seems that you have a CUDA installed under home/gw/jetson/usr/local/cuda/ as well.

Are you setting the device with JetPack?

Thanks.

Hi, I’ve set the device with JetPack and clone its img.raw to host and mount it

I’ve solved the problem of this topic by setting environment variables
solution:

export PATH=/usr/local/cuda/bin:$PATH // here is wherer nvcc is

and then you can type nvcc -V to check the version of nvcc

finally, find_package(CUDAToolkit REQUIRED) in cmake can work

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.