CMake没有正确找到CUDA库 [英] CMake does not properly find CUDA library

查看:2452
本文介绍了CMake没有正确找到CUDA库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立一个需要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 .. 
- 找到CUDA:/ usr / local / cuda )
- 找到Intel TBB
- Boost版本:1.56.0
- 找到以下Boost库:
- iostreams
- program_options
- 寻找包含文件pthread.h
- 寻找包含文件pthread.h - found
- 寻找pthread_create
- 寻找pthread_create - 找不到
- 在pthreads中查找pthread_create
- 在pthreads中查找pthread_create - 未找到
- 在pthread中查找pthread_create
- 在pthread中查找pthread_create - found
- 找到的线程:TRUE
- 找不到SDL(缺少:SDL_LIBRARY SDL_INCLUDE_DIR)
- 配置完成
- 生成完成
- 生成文件已写入:/ home / i11 / staudt / workspace / clutbb / cluster / build

但是链接器步骤失败:

  staudt〜/ workspace / clutbb / cluster / build $ make 
[69%] $ b Linking CXX executable clu
CMakeFiles / clu.dir / clu.cpp.o:在函数`initCUDA(int& CUctx_st *& int const&)'中:
clu.cpp: .text + 0x517):未定义引用`cuInit'
clu.cpp :(。text + 0x52b):未定义引用`cuDeviceGet'
clu.cpp :(。text + 0x53f):undefined到`cuCtxCreate_v2'
clu.cpp :(。text + 0x559):未定义引用`cuDeviceGetName'
clu.cpp :(。text + 0x55e):未定义引用`cuCtxSynchronize'
CMakeFiles / clu.dir / clu.cpp.o:在函数`exitCUDA(int& CUctx_st *&)':
clu.cpp :(。text + 0x684):未定义引用`cuCtxDestroy_v2'
CMakeFiles / clu.dir / clu.cpp.o:在函数`main'中:
clu.cpp :( .text.startup + 0x1092):未定义引用`cuCtxDestroy_v2'
clu.cpp :(。text.startup + 0x10d1):未定义的引用`cuCtxSynchronize'
clu.cpp :( .text.startup + 0x10e1):未定义引用`cuCtxSynchronize'
collect2:error:ld返回1退出状态
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?

解决方案

在现在发布的存档中,有多个项目层次结构。您在该问题中发布的实际错误是在基于cluutp的clutbb / cluster / bin目录中的clu项目的编译和链接期间发生的。



在此同一个目录下,有一个CMakeLists.txt文件。



在这个特定的CMakeLists.txt文件中,有以下部分:

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

尝试将上面的中间行修改为:

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

这应该修复链接器命令行中缺少的 -lcuda 。它可能仍然需要给它的路径 libcuda.so 在您的机器上,但它可能没有必要,这取决于您的机器环境设置。 p>

I'm trying to build 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 normally:

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 step 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 at /usr/local/cuda/lib64/stubs/libcuda.so, but how can I point that out to cmake or make?

解决方案

In the archive you have now posted, there are multiple project hierarchies. The actual error you have posted in the question is occurring during compile and linking of the clu project based on clu.cpp in the clutbb/cluster/bin directory.

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

In this particular CMakeLists.txt file, there is 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 modifying the middle line above to:

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

This should fix the missing -lcuda in the linker command line. It may still be necessary to give it the path to libcuda.so on your machine, but it may not be necessary, depending on how your machine environment is set up.

这篇关于CMake没有正确找到CUDA库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆