As part of a larger CMake project, I am adding a CUDA library. The rest of the project is C++, compiled with clang.
To test that the library works correctly, I'm creating a small executable and linking the CUDA library to it:
add_library(kernels STATIC
kernels.cu
)
set_target_properties(kernels PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
# --- Test executable
add_executable(main
main.cpp
)
target_link_libraries(main PRIVATE kernels)
The library compiles fine, but I get the following error when nvcc
is invoked to do the device linking part of the process on my executable (target main
):
nvlink fatal : Could not find fatbin in '[some long path]/main.cpp.o'
nvlink fatal : elfLink internal error
What is preventing this step from working?
I couldn't reproduce this issue in a fresh, tiny CMake project, so I eventually figured out that some flag from my larger project wasn't playing along.
It turns out that Thin LTO, which was enabled in CMAKE_CXX_FLAGS
is causing this issue.
I disabled it for this particular target with:
target_compile_options(main PRIVATE "-fno-lto")