Linking of CUDA library in CMake

浪尽此生 提交于 2019-12-01 08:19:04

I got this to work by calling

find_package(CUDA 9.0 REQUIRED)

in both CMake files. Also, in the Algo file (which contains the device code), I had to do

target_link_libraries(${PROJECT_NAME} ${CUDA_LIBRARIES})

I was expecting that the language support for CUDA would make those steps unnecessary, but apparently not.

I just ran into something very similar to this where the root problem was that most of my binary was being compiled with my system cxx compiler, and the cuda bits were being compiled with the cuda gcc compiler (9.1 for system, 8.3 for cuda).

Surprisingly it was fixed by changing:

project(MyProject LANGUAGES CXX CUDA)

to

project(MyProject LANGUAGES CUDA CXX)

After that change, CMake picked up the cuda version of the gcc compiler as the main compiler, and my binary started building again. I'm not sure if this could introduce problems for other packages, but it fixed the linking problem I was hitting.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!