I am trying to compile a few .cu source files into a python module. Which works fine as long as there is not more than one file. The CMakeLists.txt looks like this:
find_package(CUDA)
find_package(PythonLibs 3.7 REQUIRED)
find_package(pybind11)
file(GLOB_RECURSE sources ${SRC}/launcher.cu)
cuda_add_library(main SHARED ${SRC}/module.cpp ${sources})
target_link_libraries(main ${PYTHON_LIBRARIES} cudart)
set_target_properties(main PROPERTIES CUDA_SEPERABLE_COMPILATION ON)
The above file will compile a python module neatly
But when ${sources}
contains several .cu file, the linking just doesn't happen. I receive the following error:
[ 16%] Building NVCC (Device) object CMakeFiles/main.dir/src/main_generated_launcher.cu.o ptxas fatal : Unresolved extern function '_ZN5StateIdE16WithinBoundariesEii' CMake Error at main_generated_launcher.cu.o.cmake:279 (message): Error generating file [...]/DNA_PredatorPrey/build/CMakeFiles/main.dir/src/./main_generated_launcher.cu.o
The "Unresolved extern function points" is a function that the linker is supposed to find in another source file.
When using add_executable(....)
instead of cuda_add_library
on the exact same group of files, it will compile into a working executable file.
So I'm looking for what cuda_add_library
requires in order to link files properly.