I am new to CMake. I have the following source files:
I have the following two issues that I am bouncing between:
/usr/bin/ld: cannot find CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/cmake_device_link.o: No such file or directory
and
nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
And yes /cmake_device_link.o is not created though there is no errors that I can see as to why.
## [main]
if(NOT DEFINED ${CMAKE_BUILD_TYPE})
set(CMAKE_BUILD_TYPE "Debug")
endif()
# Almost all CMake files should start with this
# You should always specify a range with the newest
# and oldest tested versions of CMake. This will ensure
# you pick up the best policies. CUDA started at v3.8.
cmake_minimum_required(VERSION 3.8...3.27)
message(STATUS ">>Static library CUDA kernels build started")
# set the project name
project(StaticLibraryMakeCUDAKernel
VERSION 1.0
DESCRIPTION "Static library holding CUDA kernels"
LANGUAGES CXX CUDA)
# If you set any CMAKE_ variables, that can go here.
# (But usually don't do this, except maybe for C++ standard)
## [start set variables]
# Let's nicely support folders in IDEs
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(TARGET_NAME StaticLibOfFnsCUDAKernelcmake_d)
set(STATIC_LIB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/StaticLibraryMakeCUDAKernel/src")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -rdc=true")
string(APPEND CMAKE_CUDA_FLAGS " -c")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
string(APPEND CMAKE_CXX_FLAGS " -G")
string(APPEND CMAKE_CXX_FLAGS " -O0")
endif()
set(STATIC_LIB_FILES "${STATIC_LIB_INCLUDE_DIR}/library.cu")
#"${STATIC_LIB_INCLUDE_DIR}/cudakernels.cu"
#"${STATIC_LIB_INCLUDE_DIR}/staticlibfnscudakernel.h")
## [end set variables]
# Find packages go here
## [find_package]
# Dynamic parallelism requires relocatable device code linking, in addition to compiling.
find_package(CUDA REQUIRED)
## [find_package]
## [core]
# Sets up global settings
# add other deeper CMakeList sub directories
# Create the static library
## [add_and_link]
add_library(${TARGET_NAME} SHARED ${STATIC_LIB_FILES})
# Request that particles be built with -std=c++11
# As this is a public compile feature anything that links to particles
# will also build with -std=c++11
target_compile_features(${TARGET_NAME} PUBLIC cxx_std_11)
# We need to explicitly state that we need all CUDA files in this
# library to be built with -dc as the member functions could be called by
# other libraries and executables
#set_property(TARGET ${TARGET_NAME} PROPERTY CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(${TARGET_NAME} PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)
# Enables both relocatable device code compiling and linking:
set_target_properties(${TARGET_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(${TARGET_NAME} PROPERTIES CUDA_ARCHITECTURES "75")
target_link_libraries(${TARGET_NAME} PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
## [add_and_link]
## [core]
## [main]
message(STATUS "<<Static library CUDA kernels build finished")
The output from make is as follows when specifying more than one source file:
[ 16%] Building CUDA object StaticLibraryMakeCUDAKernel/CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/src/library.cu.o
[ 33%] Building CUDA object StaticLibraryMakeCUDAKernel/CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/src/cudakernels.cu.o
[ 50%] Linking CUDA device code CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/cmake_device_link.o
/usr/local/cuda-12.0/bin/nvcc -forward-unknown-to-host-compiler -rdc=true -c -g --generate-code=arch=compute_75,code=[compute_75,sm_75] -Xcompiler=-fPIC -Wno-deprecated-gpu-targets -shared -dlink CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/src/library.cu.o CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/src/cudakernels.cu.o -o CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/cmake_device_link.o -ldl -lcudadevrt -lcudart_static -lrt -lpthread
**nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified**
make[2]: *** [StaticLibraryMakeCUDAKernel/CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/build.make:116: StaticLibraryMakeCUDAKernel/CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/cmake_device_link.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:117: StaticLibraryMakeCUDAKernel/CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
or when a single .cu file is specified:
[ 20%] Building CUDA object StaticLibraryMakeCUDAKernel/CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/src/library.cu.o
[ 40%] Linking CUDA device code CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/cmake_device_link.o
/usr/local/cuda-12.0/bin/nvcc -forward-unknown-to-host-compiler -rdc=true -c -g --generate-code=arch=compute_75,code=[compute_75,sm_75] -Xcompiler=-fPIC -Wno-deprecated-gpu-targets -shared -dlink CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/src/library.cu.o -o CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/cmake_device_link.o -ldl -lcudadevrt -lcudart_static -lrt -lpthread
[ 60%] Linking CUDA shared library libStaticLibOfFnsCUDAKernelcmake_d.so
/usr/bin/g++ -fPIC -shared -Wl,-soname,libStaticLibOfFnsCUDAKernelcmake_d.so -o libStaticLibOfFnsCUDAKernelcmake_d.so CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/src/library.cu.o CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/cmake_device_link.o -ldl -lcudadevrt -lcudart_static -lrt -lpthread -ldl -L"/usr/local/cuda-12.0/targets/x86_64-linux/lib/stubs" -L"/usr/local/cuda-12.0/targets/x86_64-linux/lib"
**/usr/bin/ld: cannot find CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/cmake_device_link.o: No such file or directory**
collect2: error: ld returned 1 exit status
make[2]: *** [StaticLibraryMakeCUDAKernel/CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/build.make:118: StaticLibraryMakeCUDAKernel/libStaticLibOfFnsCUDAKernelcmake_d.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:117: StaticLibraryMakeCUDAKernel/CMakeFiles/StaticLibOfFnsCUDAKernelcmake_d.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
If the first issue is not really a problem in that all the source files are found and compiled, then why is a cmake_device_link.o is not be produced?
Any clues as to how to fix this would be awesome.
Note: my other CMAKE statements may not be correct.