【发布时间】:2015-01-17 01:25:42
【问题描述】:
我正在尝试构建一个需要 CUDA 的程序。对于我提供的 CMake 脚本:
cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda ..
找到CUDA,CMake运行正常:
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
但随后链接器步骤失败:
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
所需的库位于/usr/local/cuda/lib64/stubs/libcuda.so,但我如何将其指出给 cmake 或 make?
【问题讨论】:
-
应该链接的
libcuda.so通常不是您显示的目录中的那个。正确的libcuda.so由驱动程序 安装,而不是CUDA 安装程序。它通常可以在/usr/lib64或类似的地方找到。在某个地方,您的制作过程中缺少-lcuda,或者库目录搜索路径未设置为指向您机器上libcuda.so的正确位置。/usr/local/cuda/...通常不是寻找libcuda.so的正确位置 -
链接器命令是
/usr/bin/c++ -O3 -Wall -ffast-math -DNDEBUG -DLEAN CMakeFiles/clu.dir/clu.cpp.o -o clu -rdynamic /usr/local/cuda/lib64/libcudart.so -ltbb -lboost_iostreams-mt -lboost_program_options-mt -lrt ../src/libcluster.a /usr/local/cuda/lib64/libcudart.so -Wl,-rpath,/usr/local/cuda/lib64没有-lcuda,我也不知道怎么加。 -
我稍微更新了我的回复,看看是否能解决您的问题。
-
我对讨论有点困惑:显然 CMake 报告它找到了 CUDA 但未能生成
-lcudalinker 标志,对吧? -
简而言之,CUDA 应用分为 2 类。驱动程序 API 应用程序和使用运行时 API 的应用程序。可以说更常见的运行时 API 应用程序不需要链接到 libcuda。所以 CMake “发现” CUDA 大概意味着它被设置为构建一个运行时 API CUDA 应用程序。您将需要了解如何在 CMake 中按下魔法按钮来构建驱动程序 API 应用程序。我不是 CMake 专家。如果您在 CUDA 标签中阅读了您之前的问题,它将讨论驱动程序 API 与运行时 API。 Anycorn 的答案,主要是关于路径,不会解决缺少
-lcuda的问题,我不认为。