Nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified

Hi everyone, I am working on making python bindings for a c++ project with some CUDA kernels in it. To do this I am making use of the nanobind library and CMake. Unfortunately, when running the build I currently run into the following error: “nvcc fatal: A single input file is required for a non-link phase when an outputfile is specified” which I don’t know how to solve.

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.15...3.27)
project(my_project LANGUAGES CXX CUDA)
enable_language(CUDA)

# Warn if the user invokes CMake directly
if (NOT SKBUILD)
  message(WARNING <Nanobind standard warning is here>)
endif()

# Try to import all Python components potentially needed by nanobind
find_package(Python 3.11
    REQUIRED COMPONENTS Interpreter Development.Module
    OPTIONAL_COMPONENTS Development.SABIModule
)
find_package(nanobind CONFIG REQUIRED)
find_package(CUDAToolkit REQUIRED)

set(MY_PROJECT_SOURCES
    # Source files go here
    src/pch.cpp
    src/types.cpp
    src/logging.cpp
    src/display.cpp
    src/main.cpp
)

set(MY_PROJECT_INCLUDES
    # Include folders go here
    Dependencies/x64/argparse/include
    Dependencies/x64/CImg/include
    Dependencies/x64/cuFFTDx/include
    Dependencies/x64/fftw/include
    Dependencies/x64/glm/include
    Dependencies/x64/libpng/include
    Dependencies/x64/zlib/include
    ${CUDAToolkit_INCLUDE_DIRS}
)

set(MY_PROJECT_DEPENDENCIES
    "${CMAKE_SOURCE_DIR}/Dependencies/x64/fftw/lib/libfftw3-3.lib"
    "${CMAKE_SOURCE_DIR}/Dependencies/x64/fftw/lib/libfftw3f-3.lib"
    "${CMAKE_SOURCE_DIR}/Dependencies/x64/libpng/lib/libpng16.lib"
    "${CMAKE_SOURCE_DIR}/Dependencies/x64/libpng/lib/libpng16_static.lib"
    "${CMAKE_SOURCE_DIR}/Dependencies/x64/zlib/lib/zlib.lib"
    "${CMAKE_SOURCE_DIR}/Dependencies/x64/zlib/lib/zlibstatic.lib"
    CUDA::cufft
    CUDA::cudart
    #${CUDAToolkit_LIBRARY_DIR}
)

add_library(MY_PROJECT_CUDA_KERNELS STATIC my-project/src/kernels.cu)
set_target_properties(MY_PROJECT_CUDA_KERNELS
    PROPERTIES
    POSITION_INDEPENDENT_CODE ON
    CUDA_VISIBILITY_PRESET "hidden"
    CUDA_SEPARABLE_COMPILATION ON
)

target_link_libraries(MY_PROJECT_CUDA_KERNELS PRIVATE ${MY_PROJECT_DEPENDENCIES} ${Python_LIBRARIES})
target_include_directories(MY_PROJECT_CUDA_KERNELS PRIVATE ${MY_PROJECT_INCLUDES})

add_library(MY_PROJECT_LIBRARY STATIC ${MY_PROJECT_SOURCES})
set_target_properties(MY_PROJECT_LIBRARY
    PROPERTIES
    CXX_STANDARD 17
    POSITION_INDEPENDENT_CODE ON
    CUDA_VISIBILITY_PRESET "hidden"
    CUDA_SEPARABLE_COMPILATION ON
)

target_link_libraries(MY_PROJECT_LIBRARY PRIVATE ${MY_PROJECT_DEPENDENCIES} ${MY_PROJECT_CUDA_KERNELS})
target_include_directories(MY_PROJECT_LIBRARY PRIVATE ${MY_PROJECT_INCLUDES})

nanobind_add_module(my_project_ext
    STABLE_ABI
    NB_STATIC
    src/my_project_ext.cpp
    ${MY_PROJECT_SOURCES}
    src/kernels.cu
)

target_link_libraries(my_project_ext PRIVATE ${MY_PROJECT_DEPENDENCIES} ${MY_PROJECT_LIBRARY})
target_include_directories(my_project _ext PRIVATE ${MY_PROJECT_INCLUDES})

install(TARGETS my_project_ext LIBRARY DESTINATION my_project)

Furthermore, if necessary, here is the full error message:

"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\bin\nvcc.exe"  --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\bin\HostX64\x64" -x cu   -I"C:\Users\<user>\Documents\my-project\Dependencies\x64\argparse\include" -I"C:\Users\<user>\Documents\my-project\Dependencies\x64\CImg\include" -I"C:\Users\<user>\Documents\my-project\Dependencies\x64\cuFFTDx\include" -I"C:\Users\<user>\Documents\my-project\Dependencies\x64\fftw\include" -I"C:\Users\<user>\Documents\my-project\Dependencies\x64\glm\include" -I"C:\Users\<user>\Documents\my-project\Dependencies\x64\libpng\include" -I"C:\Users\<user>\Documents\my-project\Dependencies\x64\zlib\include" -I"C:\Users\<user>\AppData\Local\Programs\Python\Python311\Lib\site-packages\nanobind\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\include" -IC:\Users\<user>\AppData\Local\Programs\Python\Python311\Include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\include"     --keep-dir x64\Release  -maxrregcount=0   --machine 64 --compile -cudart static -std=c++17 --generate-code=arch=compute_52,code=[compute_52,sm_52] /bigobj /MP /Os -Xcompiler="/EHsc -Ob2"   -D_WINDOWS -DNDEBUG -D"CMAKE_INTDIR=\"Release\"" -Dmy_project_ext_EXPORTS -D_WINDLL -D_MBCS -DWIN32 -D_WINDOWS -DNDEBUG -D"CMAKE_INTDIR=\"Release\"" -Dmy_project_ext_EXPORTS -Xcompiler "/EHsc /W1 /nologo /O2 /FS   /MD " -Xcompiler "/Fdmy_project_ext.dir\Release\vc143.pdb" -o my_project_ext.dir\Release\kernels.obj "C:\Users\<user>\Documents\my-project\src\kernels.cu"
        nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified

I’m a bit at a loss why I am getting this error message. I saw in an earlier post of similar nature that the cause could be spaces in the path to the file but I have tested this on my laptop and it still gave the very same error. Any help would be appreciated!

The command line processing of nvcc considers anything that is not recognized as a valid command-line switch a file name. A common source of this kind of error are incorrectly configured build rules. This part of this particular nvcc invocation looks suspicious:

/bigobj /MP /Os

It probably belongs inside the -Xcompiler argument string, as these look like command-line switches for MSVC.

Ah okay, I am not 100% sure but I think those are there because of nanobind. I’ll see if I can move them/get rid of them in some way. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.