NVCC fatal error, make: *** [cudaobj/Debug/fkt_alles_cuda.o] Error 1 - Solved

Hello there,

I’m trying to compile CUDA code on an Jetson TX2, resulting in the error “nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified”.
The code has already run without CUDA, so I suspect that the integration of the CUDA code is the problem. CUDA itself is correctly installed, since the exmaples compiled and run.

Versions:

Ubuntu 16.04 LTS
Qt Creator 3.5.1
cmake version 3.5.1
cuda-9.0
nvcc V9.0.252
openCV 3.3.1

Compile output:

14:34:30: Running steps for project CudaPic...
14:34:30: Configuration unchanged, skipping qmake step.
14:34:30: Starting: "/usr/bin/make" 
/usr/lib/aarch64-linux-gnu/qt5/bin/qmake -spec linux-g++ CONFIG+=debug -o Makefile ../CudaPic/CudaPic.pro
WARNING: Compiler: cuda: No output file specified
/usr/local/cuda-9.0/bin/nvcc -D_DEBUG -D/usr/local/cuda-9.0 -lcudart -lcuda --machine 64 sm_62 -c -o cudaobj/Debug/fkt_alles_cuda.o ../CudaPic/fkt_alles.cu
Makefile:318: recipe for target 'cudaobj/Debug/fkt_alles_cuda.o' failed
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
make: *** [cudaobj/Debug/fkt_alles_cuda.o] Error 1
14:34:30: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project CudaPic (kit: JetsonTX2)
When executing step "Make"
14:34:30: Elapsed time: 00:00.

Project Files:

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

## SYSTEM_TYPE - compiling for 32 or 64 bit architecture
SYSTEM_TYPE = 64

SOURCES += main.cpp \
    tcamimage.cpp \
    tcamcamera.cpp

HEADERS += \
    tcamimage.h \
    tcamcamera.h \
    fkt_alles_emxutil.h \
    fkt_alles_initialize.h \
    fkt_alles_terminate.h \
    fkt_alles_types.h \
    fkt_alles.h \
    MWCudaDimUtility.h \
    rt_nonfinite.h \
    rtGetInf.h \
    rtGetNaN.h \
    rtwtypes.h

# Cuda sources
CUDA_SOURCES += fkt_alles.cu
CUDA_SOURCES += fkt_alles_emxutil.cu
CUDA_SOURCES += fkt_alles_initialize.cu
CUDA_SOURCES += fkt_alles_terminate.cu
CUDA_SOURCES += MWCudaDimUtility.cu
CUDA_SOURCES += rt_nonfinite.cu
CUDA_SOURCES += rtGetInf.cu
CUDA_SOURCES += rtGetNaN.cu

# Path to cuda toolkit install
CUDA_SDK      = /usr/local/cuda-9.0/samples
CUDA_DIR      = /usr/local/cuda-9.0

CUDA_DEFINES += /usr/local/cuda-9.0

# Path to header and libs files
INCLUDEPATH  += $$CUDA_DIR/include
INCLUDEPATH  += $$CUDA_SDK/common/inc
INCLUDEPATH  += $$CUDA_SDK/../shared/inc

QMAKE_LIBDIR += $$CUDA_DIR/lib64
QMAKE_LIBDIR += $$CUDA_SDK/common/lib/linux

#CUDA_OBJECTS_DIR = ./
# libs used in your code
LIBS += -lcudart -lcuda
CUDA_LIBS = -lcudart -lcuda
# GPU architecture
CUDA_COMPUTE_ARCH = 62
CUDA_ARCH = sm_62
# Here are some NVCC flags I've always used by default.
NVCCFLAGS     = --use_fast_math --ptxas-options=-v

## correctly formats CUDA_DEFINES for nvcc
for(_defines, CUDA_DEFINES):{
    formatted_defines += -D$$_defines
}
CUDA_DEFINES = $$formatted_defines

QMAKE_EXTRA_COMPILERS += cuda

unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += gstreamer-1.0

unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += gstreamer-video-1.0

unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += gtk+-3.0

unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += gobject-introspection-1.0

unix: CONFIG += link_pkgconfig
unix: PKGCONFIG += tcam

LIBS += `pkg-config opencv --libs`

unix: PKGCONFIG += gstreamer-app-1.0

DISTFILES += \
    fkt_alles_terminate.cu \
    MWCudaDimUtility.cu \
    rt_nonfinite.cu \
    rtGetInf.cu \
    rtGetNaN.cu \
    fkt_alles_emxutil.cu \
    fkt_alles_initialize.cu \
    fkt_alles.cu

#nvcc config
CONFIG(debug, debug|release) {
        #Debug settings
        CUDA_OBJECTS_DIR = cudaobj/$$SYSTEM_NAME/Debug
        cuda_d.input = CUDA_SOURCES
        cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
        cuda_d.commands = $$CUDA_DIR/bin/nvcc -D_DEBUG $$CUDA_DEFINES $$NVCC_OPTIONS $$CUDA_INC $$CUDA_LIBS --machine $$SYSTEM_TYPE $$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
        cuda_d.dependency_type = TYPE_C
        QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
        # Release settings
        CUDA_OBJECTS_DIR = cudaobj/$$SYSTEM_NAME/Release
        cuda.input = CUDA_SOURCES
        cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
        cuda.commands = $$CUDA_DIR/bin/nvcc $$CUDA_DEFINES $$NVCC_OPTIONS $$CUDA_INC $$CUDA_LIBS --machine $$SYSTEM_TYPE $$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
        cuda.dependency_type = TYPE_C
        QMAKE_EXTRA_COMPILERS += cuda
}

## correctly formats CUDA_COMPUTE_ARCH to CUDA_ARCH with code gen flags
## resulting format example: -gencode arch=compute_20,code=sm_20
for(_a, CUDA_COMPUTE_ARCH):{
    formatted_arch =$$join(_a,'',' -gencode arch=compute_',',code=sm_$$_a')
    CUDA_ARCH += $$formatted_arch
}

The layout for the Project-File is taken from this instruction: https://nidclip.wordpress.com/2014/04/07/setting-up-nvcc-for-cuda-in-qt/. I hope that this is some glaringly obvious mistake that a noob such as myself just doesn’t see, and that somebody can point it out.

not sure if it matters, but I use regular c++ for picture recording via cam, then process said picture via matlab code that was automatically “translated” into c++ and integrated into the project. worked fine when it was just translated to c++, gave me this error when translated into CUDA.
I assume that the designation of the output path might be false, but this point it’s nothing more than a guess.

Thank’s to everybody who makes time to help!

Without going into any other details, since I don’t use QT, Cmake and OpenCV, line #7 in the compilation output shows a problem.
You have to look line #318 of your Makefile and see if it has something that translates to:

nvcc source_1.cu source_2.cu -c -o an_object.o

It is telling you that this is not allowed. If you are not linking, then it has to be 1 source file to 1 object file. For example:

nvcc source_1.cu -c -o object_1.o
nvcc source_2.cu -c -o object_2.o

Yes, since the fatal error message suggests that a single input file is required this idea seems reasonable. or maybe the pathing is wrong, not quite sure yet…
Line 6 shows the nvcc compile command in question:

/usr/local/cuda-9.0/bin/nvcc -D_DEBUG -D/usr/local/cuda-9.0 -lcudart -lcuda --machine 64 sm_62 -c -o cudaobj/Debug/fkt_alles_cuda.o ../CudaPic/fkt_alles.cu

as far as I am aware there’s only one reference to a cuda code source in this line, but then again I’m just starting to get a grasp of the format.
for now I’ll try to understand the source of the problem, and then maybe I’ll get an idea where I have to adjust the project file.

Isuspect the problem occuring in the nvcc config part of my project file, somewhere after line 101.

Thanks for the input.

The problem is here:

sm_62

that is not a valid compiler switch, so its getting interpreted as a source file.

I’m not familiar with Qt, however that line in your project file certainly does not match the construction indicated in the reference you linked. You seem to have cut out some important lines there.

You may want to try something like:

CUDA_ARCH = “-arch=sm_62”

yeah that definitely was one of the problems. thanks a lot.

for anyone interested, here is the revised project file. still have to hunt down a few problems, but I guess that these are in the cuda code itself.

FYI, I left the the declaration of the cuda architecture as is (Line58: CUDA_ARCH = sm_62), and changed the compiler argument at Line66 to: -arch=$$CUDA_ARCH

TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt

## SYSTEM_TYPE - compiling for 32 or 64 bit architecture
SYSTEM_TYPE = 64

SOURCES += \
    main.cpp \
    tcamimage.cpp \
    tcamcamera.cpp

HEADERS += \
    tcamimage.h \
    tcamcamera.h \
    fkt_alles_emxutil.h \
    fkt_alles_initialize.h \
    fkt_alles_terminate.h \
    fkt_alles_types.h \
    fkt_alles.h \
    MWCudaDimUtility.h \
    rt_nonfinite.h \
    rtGetInf.h \
    rtGetNaN.h \
    rtwtypes.h

# Cuda sources
CUDA_SOURCES += fkt_alles.cu
CUDA_SOURCES += fkt_alles_emxutil.cu
CUDA_SOURCES += fkt_alles_initialize.cu
CUDA_SOURCES += fkt_alles_terminate.cu
CUDA_SOURCES += MWCudaDimUtility.cu
CUDA_SOURCES += rt_nonfinite.cu
CUDA_SOURCES += rtGetInf.cu
CUDA_SOURCES += rtGetNaN.cu

# Path to cuda installation
CUDA_DIR = /usr/local/cuda

#CUDA_DEFINES += /usr/local/cuda-9.0

# Path to header and libs files
INCLUDEPATH += \
               $$CUDA_DIR/include \
               $$CUDA_DIR/samples/common/inc

QMAKE_LIBDIR += \
                $$CUDA_DIR/lib64 \
                $$CUDA_DIR/samples/common/inc

# libs used in your code
LIBS += -lcudart -lcuda #-gstreamer-1.0 -gstreamer-video-1.0 -gtk+-3.0 -gobject-introspection-1.0 -tcam -gstreamer-app-1.0

# GPU architecture
CUDA_ARCH = sm_62 # http://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/

NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
-c

# Prepare the extra compiler configuration (taken from the nvidia forum)
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')

cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -c -arch=$$CUDA_ARCH -c $$NVCCFLAGS \
                $$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT} \
                2>&1 | sed -r \"s/\\(([0-9]+)\\)/:\\1/g\" 1>&2

cuda.dependency_type = TYPE_C
cuda.depend_command = $$CUDA_DIR/bin/nvcc -M $$CUDA_INC $$NVCCFLAGS ${QMAKE_FILE_NAME}

cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}.o

QMAKE_EXTRA_COMPILERS += cuda

thanks a lot for the input, Mr. Crovella.