cuda shared library linking: undefined reference to cudaRegisterLinkedBinary

后端 未结 2 959
旧巷少年郎
旧巷少年郎 2020-12-16 17:27

Goal:

  1. create a shared library containing my CUDA kernels that has a CUDA-free wrapper/header.
  2. create a test executable for the shared l
2条回答
  •  攒了一身酷
    2020-12-16 17:55

    The other answers did not work for me (maybe because I’m using cuda 10). The solution that worked for me was compiling the cuda files as:

    nvcc -dc -o cuda_file.o cuda_file.cu
    

    Than compiling the c++ file as:

    g++ -c -o cpp_file.o cpp_file.cpp
    

    And finally linking all using nvcc:

    nvcc -o my_prog cpp_file.o cuda_file.o -lcudart -lcuda -L
    

    Don’t take this code literally. But the core of the solution to the error was using nvcc instead of g++ in the final linking step.

提交回复
热议问题