My project fails in the linking step. I tried to create a minimal reproducible example for my question but failed to create one. Although the error might be identifiable from the linking command.
The command in the project that fails looks like the following:
[ 1%] Linking CUDA executable ../../../../../benchmarks/exahype2/euler/cuda-kernel-benchmarks/kernel-benchmark-fv-2d-patch-size-17
cd /home/primrose/Work/Peano/build/build/benchmarks/exahype2/euler/cuda-kernel-benchmarks && /usr/bin/cmake -E cmake_link_script CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/link.txt --verbose=1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/compilers/bin/nvc++ -g "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/AbstractEulerFVRusanov.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/EulerFVRusanov.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/tasks/EulerFVRusanovEnclaveTask.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/repositories/SolverRepository.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/celldata/EulerFVRusanovCellLabel.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/celldata/EulerFVRusanovQ.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/facedata/EulerFVRusanovQOld.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/facedata/EulerFVRusanovQNew.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/facedata/EulerFVRusanovQUpdate.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/facedata/EulerFVRusanovFaceLabel.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/repositories/DataRepository.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGrid2exahype2_solvers_fv_actionsets_InitialCondition0.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGrid2exahype2_grid_FaceLabel1.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGrid2exahype2_grid_CellLabel2.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGrid2exahype2_solvers_fv_actionsets_AdaptivityCriterion3.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGrid2exahype2_grid_CellLabel4.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGrid.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_solvers_fv_actionsets_DynamicAMR0.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2peano4_toolbox_blockstructured_BackupPatchOverlap1.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_solvers_fv_actionsets_RollOverUpdatedFace2.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_solvers_fv_actionsets_InitialCondition3.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_solvers_fv_actionsets_ProjectPatchOntoFaces4.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_grid_FaceLabel5.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_grid_CellLabel6.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_solvers_fv_actionsets_AdaptivityCriterion7.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_solvers_fv_actionsets_PostprocessSolution8.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid2exahype2_grid_CellLabel9.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/InitGrid.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridButPostponeRefinement2exahype2_solvers_fv_actionsets_InitialCondition0.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridButPostponeRefinement2exahype2_grid_FaceLabel1.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridButPostponeRefinement2exahype2_grid_CellLabel2.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridButPostponeRefinement2exahype2_solvers_fv_actionsets_AdaptivityCriterion3.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridButPostponeRefinement2exahype2_grid_CellLabel4.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridButPostponeRefinement.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridAndConvergeLoadBalancing2exahype2_solvers_fv_actionsets_InitialCondition0.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridAndConvergeLoadBalancing2exahype2_grid_FaceLabel1.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridAndConvergeLoadBalancing2exahype2_grid_CellLabel2.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridAndConvergeLoadBalancing2exahype2_solvers_fv_actionsets_AdaptivityCriterion3.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridAndConvergeLoadBalancing2exahype2_grid_CellLabel4.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/CreateGridAndConvergeLoadBalancing.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/PlotSolution2exahype2_solvers_fv_actionsets_DynamicAMR0.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/PlotSolution2exahype2_solvers_fv_actionsets_RollOverUpdatedFace1.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/PlotSolution2exahype2_grid_FaceLabel2.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/PlotSolution2exahype2_grid_CellLabel3.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/PlotSolution2exahype2_solvers_fv_actionsets_ProjectPatchOntoFaces4.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/PlotSolution2peano4_toolbox_blockstructured_PlotPatchesInPeanoBlockFormat5.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/PlotSolution.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_solvers_fv_EnclaveTasking0.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_solvers_fv_actionsets_DynamicAMR1.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_solvers_fv_actionsets_RollOverUpdatedFace2.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_grid_FaceLabel3.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_grid_CellLabel4.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_solvers_fv_actionsets_HandleBoundary5.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2peano4_toolbox_blockstructured_ReconstructPatchAndApplyFunctor6.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_solvers_fv_actionsets_ProjectPatchOntoFaces7.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_solvers_fv_actionsets_AdaptivityCriterion8.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep2exahype2_solvers_fv_actionsets_PostprocessSolution9.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/observers/TimeStep.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/repositories/StepRepository.cu.o" "CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/EulerFVRusanovKernelBenchmarks-main.cu.o" -o ../../../../../benchmarks/exahype2/euler/cuda-kernel-benchmarks/kernel-benchmark-fv-2d-patch-size-17 -L/home/primrose/Work/Peano/build -Wl,-rpath,/home/primrose/Work/Peano/build -lPeano4Core2d_asserts -lExaHyPE2Core2d_asserts -cuda -lcudadevrt -lcudart_static -lrt -lpthread -ldl -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/12.0/lib64" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/math_libs/12.0/lib64" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/comm_libs/12.0/nccl/lib" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/comm_libs/12.0/nvshmem/lib" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/12.0/targets/x86_64-linux/lib/stubs" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/12.0/targets/x86_64-linux/lib"
/usr/bin/ld:CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/AbstractEulerFVRusanov.cu.o: file format not recognized; treating as linker script
/usr/bin/ld:CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/AbstractEulerFVRusanov.cu.o:18: syntax error
pgacclnk: child process exit status 1: /usr/bin/ld
I have checked that the linker script CMakeFiles/kernel-benchmark-fv-2d-patch-size-17.dir/link.txt indeed exists therefore I do not understand why this error is given. Furthermore in the stub project I created to create a minimally reproducible the linking step does not fail:
[100%] Linking CUDA executable main
/usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/compilers/bin/nvc++ -g CMakeFiles/main.dir/main.cu.o CMakeFiles/main.dir/extra.cu.o -o main /opt/nvidia/hpc_sdk/Linux_x86_64/23.1/compilers/lib/libacchost.so -lcudadevrt -lcudart_static -lrt -lpthread -ldl -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/12.0/lib64" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/math_libs/12.0/lib64" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/comm_libs/12.0/nccl/lib" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/comm_libs/12.0/nvshmem/lib" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/12.0/targets/x86_64-linux/lib/stubs" -L"/opt/nvidia/hpc_sdk/Linux_x86_64/23.1/cuda/12.0/targets/x86_64-linux/lib"
make[2]: Leaving directory '/home/primrose/Work/aux/cuda_test_room/build'
[100%] Built target main
It gives me following output, only difference that I see and suspect that might have an impact looks like the quote marks around the object files (.o(. Also I want to mention that I have set nvc++ as the host compiler in the CMake configuration before enabling CUDA language.
If needed I can provide the CMake Files of both projects.
As a notice in the real project, the CMakeList.txt and the Source files (all cuda files) are generated by a set of python scripts and added to a pre-existing pure C++ libraries. The generated CMakeLists.txt and the project are added to the main CMake project. The generated CMake project links to OpenMP and some other C++ libraries.
Update:
I have managed to reproduce the issue, it occurs when I have the following link and compile options enabled:
target_link_libraries(project_options INTERFACE “-cuda”)
target_compile_options(project_options INTERFACE “-cuda”)
Basically removing “-cuda” fixes the link step, but why would adding “-cuda” would result with such an error?