CMake incorrectly locates the CUDA library

I am trying to create a program that requires CUDA. To the CMake script, I supply:

cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda ..

      

CUDA is found and CMake runs fine:

staudt ~/workspace/clutbb/cluster/build $ cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda ..                                                                                  
-- Found CUDA: /usr/local/cuda (found version "6.5") 
-- Found Intel TBB
-- Boost version: 1.56.0
-- Found the following Boost libraries:
--   iostreams
--   program_options
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Could NOT find SDL (missing:  SDL_LIBRARY SDL_INCLUDE_DIR) 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/i11/staudt/workspace/clutbb/cluster/build

      

But then the linker fails:

staudt ~/workspace/clutbb/cluster/build $ make
[ 69%] Built target cluster
Linking CXX executable clu
CMakeFiles/clu.dir/clu.cpp.o: In function `initCUDA(int&, CUctx_st*&, int const&)':
clu.cpp:(.text+0x517): undefined reference to `cuInit'
clu.cpp:(.text+0x52b): undefined reference to `cuDeviceGet'
clu.cpp:(.text+0x53f): undefined reference to `cuCtxCreate_v2'
clu.cpp:(.text+0x559): undefined reference to `cuDeviceGetName'
clu.cpp:(.text+0x55e): undefined reference to `cuCtxSynchronize'
CMakeFiles/clu.dir/clu.cpp.o: In function `exitCUDA(int&, CUctx_st*&)':
clu.cpp:(.text+0x684): undefined reference to `cuCtxDestroy_v2'
CMakeFiles/clu.dir/clu.cpp.o: In function `main':
clu.cpp:(.text.startup+0x1092): undefined reference to `cuCtxDestroy_v2'
clu.cpp:(.text.startup+0x10d1): undefined reference to `cuCtxSynchronize'
clu.cpp:(.text.startup+0x10e1): undefined reference to `cuCtxSynchronize'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/clu] Fehler 1
make[1]: *** [bin/CMakeFiles/clu.dir/all] Fehler 2
make: *** [all] Fehler 2

      

The required library is in /usr/local/cuda/lib64/stubs/libcuda.so

, but how can I point this to cmake or do it?

+3


source to share


2 answers


There are several project hierarchies in the archive you posted. The actual error you posted in the question comes up while compiling and linking a clu project based on clu.cpp in the clutbb / cluster / bin directory.

In the same directory there is a CMakeLists.txt file. This file defines this level of the project hierarchy.

This CMakeLists.txt file has the following section:

cuda_add_executable(clu clu.cpp)
target_link_libraries(clu ${CUDA_LIBRARY} ${TBB_LIBRARY} ${Boost_LIBRARIES} rt)
target_link_libraries(clu cluster)

      



Try changing the middle line above:

target_link_libraries(clu ${CUDA_LIBRARY} ${TBB_LIBRARY} ${Boost_LIBRARIES} rt cuda)

      

This should fix -lcuda

the linker missing on the command line. It may still be necessary to provide the path to libcuda.so

on your machine, but this may not be necessary depending on your machine environment setup.

+4


source


The C ++ file with the host calls doesn't know what it needs to reference libcudart

. You have to explicitly install dependencies for the file / binary the file is in, eg.

target_link_libraries(clu ${CUDA_LIBRARIES})

      



The above answer is a bit wrong. It looks like libcuda.so is installed in an unexpected location for whatever reason. You can try to install CMAKE_LIBRARY_PATH

or / and CUDA_LIB_PATH

to this path.

CUDA_LIB_PATH needs to be set outside cmake, I think for example export CUDA_LIB_PATH=/usr/local/cuda/lib64/stubs/

0


source







All Articles