cmake, undefined reference cuCtxDetach, cuMemGetInfo_v2, cuCtxCreate_v2, cuInit

hi,

I got a view undefined reference with cmake. If I compile with “nvcc knn_cublas_with_indexes.cu -lcublas -lcuda” everything is fine!

Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 2.8.3)
project(test)
FIND_PACKAGE(CUDA REQUIRED)

SET(CUDA_NVCC_FLAGS "-arch=sm_13" CACHE STRING "nvcc flags" FORCE)
SET (CUDA_VERBOSE_BUILD ON CACHE BOOL "nvcc verbose" FORCE)

CUDA_ADD_EXECUTABLE(tset knn_cublas_with_indexes.cu)
CUDA_ADD_CUBLAS_TO_TARGET(tset)

I get this error:

CMakeFiles/tset.dir/./tset_generated_knn_cublas_with_indexes.cu.o: In Funktion `knn(float*, int, float*, int, int, int, float*, int*)':
/home/***/Downloads/vincentfpgarcia-kNN-CUDA-70dc929/KNN.CUBLAS.with.indexes/knn_cublas_with_indexes.cu:274: Nicht definierter Verweis auf `cuInit'
/home/***/Downloads/vincentfpgarcia-kNN-CUDA-70dc929/KNN.CUBLAS.with.indexes/knn_cublas_with_indexes.cu:279: Nicht definierter Verweis auf `cuCtxCreate_v2'
/home/***/Downloads/vincentfpgarcia-kNN-CUDA-70dc929/KNN.CUBLAS.with.indexes/knn_cublas_with_indexes.cu:280: Nicht definierter Verweis auf `cuMemGetInfo_v2'
/home/***/Downloads/vincentfpgarcia-kNN-CUDA-70dc929/KNN.CUBLAS.with.indexes/knn_cublas_with_indexes.cu:281: Nicht definierter Verweis auf `cuCtxDetach'
collect2: error: ld returned 1 exit status
make[2]: *** [tset] Fehler 1
make[1]: *** [CMakeFiles/tset.dir/all] Fehler 2
make: *** [all] Fehler 2

Please help!

Probably your cmake is set up to build runtime api applications, for which -lcuda is not required. The application you are building appears to use driver API (things like cuInit are part of the driver API) and your cmake may not be properly adding -lcuda to the link specification.

Thanks for your reply, but

how do I modify my CMakeLists.txt to use driver API?

I solved it by adding

target_link_libraries(tset cuda)