0

I am absolute learning of CUDA, and when running a CUDA script, I got an error as:

FAILED: Cuda_notes : && /usr/bin/c++ -g CMakeFiles/Cuda_notes.dir/deviceQuery.cpp.o -o Cuda_notes && : /usr/bin/ld: CMakeFiles/Cuda_notes.dir/deviceQuery.cpp.o: in function _cudaGetErrorEnum(cudaError)': /home/xxx/CUDA/Cuda_notes/cuda-samples/Common/helper_cuda.h:54: undefined reference to cudaGetErrorName' /usr/bin/ld: CMakeFiles/Cuda_notes.dir/deviceQuery.cpp.o: in function main': /home/xxx/CUDA/Cuda_notes/deviceQuery.cpp:51: undefined reference to cudaGetDeviceCount'

I want to know what command I should add to my CMakeLists.txt, which currently is:

cmake_minimum_required(VERSION 3.23)

#set(CMAKE_CUDA_COMPILER "/usr/local/cuda/bin/nvcc")
set(CMAKE_CUDA_ARCHITECTURES "35;50;52;60;61;70;75;80;86")
project(Cuda_notes LANGUAGES CUDA CXX C)
#find_package(CUDAToolkit)

set(CMAKE_CXX_STANDARD 23)

set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
include_directories(SYSTEM "${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}")
#/home/xxx/CUDA/Cuda_notes/cuda-samples/Common
include_directories(SYSTEM "/home/xxx/CUDA/Cuda_notes/cuda-samples/Common")
include_directories(.)
#link_libraries(cudart)
#target_link_libraries(cudart)

add_executable(Cuda_notes deviceQuery.cpp)

Your answer and guide will be appreciated!

Eric
  • 99
  • 6
  • 1
    Does this answer your question? [How to find and link CUDA libraries using CMake 3.15?](https://stackoverflow.com/questions/66327073/how-to-find-and-link-cuda-libraries-using-cmake-3-15) – pptaszni Nov 25 '22 at 12:43
  • 1
    Also [here](https://cmake.org/cmake/help/latest/module/FindCUDAToolkit.html) explained which targets are available and what to link against (e.g. `CUDA::cudart`). And [here](https://stackoverflow.com/questions/19980412/how-to-let-cmake-find-cuda) how to troubleshot if CUDA not found. – pptaszni Nov 25 '22 at 12:44

1 Answers1

1

Thanks for the comments and shared information. I resolve this issue with the following CMakeLists.txt as:

cmake_minimum_required(VERSION 3.23)

#set(CMAKE_CUDA_COMPILER "/usr/local/cuda/bin/nvcc")
set(CMAKE_CUDA_ARCHITECTURES "35;50;52;60;61;70;75;80;86")
project(Cuda_notes LANGUAGES CUDA CXX C)
#find_package(CUDAToolkit)

set(CMAKE_CXX_STANDARD 23)

set(CMAKE_CUDA_STANDARD 14)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
include_directories(SYSTEM "${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}")
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/cuda-samples/Common")
include_directories(.)

add_executable(Cuda_notes deviceQuery.cu)
target_link_libraries(Cuda_notes cudart)
Eric
  • 99
  • 6