'linker input file unused because linking not

2019-05-26 14:07发布

I'm trying to get started with with C and Cuda using QT creator as the IDE. Unfortunately I'm having problems from the start and not sure where its coming from(if it started gradually it'd be easier to identify).

I basically already installed CUDA(and c) and had small test programs running but I wanted to use an IDE so I installed QT creator using the instructions on: http://cudaspace.wordpress.com/2011/04/07/qt-creator-cuda-linux/ but I'm getting errors when running the example: 'linker input file unused because linking not done'

Here's all the files(with my modifications since I'm using a mac and the instructions are for linux. I can compile basic hello world type things but not the example for some reason): my_first_project.pro:

TEMPLATE = app
LANGUAGE = C++
CONFIG += qt4


SOURCES += main.cpp \
    cuda_interface.cu
# Cuda sources
CUDA_SOURCES += cuda_interface.cu
# Project dir and outputs
PROJECT_DIR = $$system(pwd)
OBJECTS_DIR = $$PROJECT_DIR/Obj
DESTDIR = ../bin

# Path to cuda SDK install
CUDA_SDK = /Users/lostsoul/Dropbox/qt_cuda/C/
# Path to cuda toolkit install
CUDA_DIR = /usr/local/cuda
# GPU architecture
CUDA_ARCH = compute_10
# nvcc flags (ptxas option verbose is always useful)
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
# include paths
INCLUDEPATH += $$CUDA_DIR/include
INCLUDEPATH += $$CUDA_SDK/common/inc/
INCLUDEPATH += $$CUDA_SDK/../shared/inc/
# lib dirs
QMAKE_LIBDIR += $$CUDA_DIR/lib64
QMAKE_LIBDIR += $$CUDA_SDK/lib
QMAKE_LIBDIR += $$CUDA_SDK/common/lib
# libs - note than i'm using a x_86_64 machine
LIBS += -lcudart -lcutil_x86_64
# join the includes in a line
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
LD_LIBRARY_PATH = /usr/local/cuda/lib

# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o

cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -g -G -arch=$$CUDA_ARCH -c $$NVCCFLAGS $$CUDA_INC $$LIBS  ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

cuda.dependcy_type = TYPE_C
cuda.depend_command = $$CUDA_DIR/bin/nvcc -g -G -M $$CUDA_INC $$NVCCFLAGS   ${QMAKE_FILE_NAME}
# Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda

cuda_interface.cu:

// CUDA-C includes
#include <cuda.h>
#include <cutil_inline.h>

extern "C"
void runCudaPart();

// Main cuda function

void runCudaPart() {

// all your cuda code here *smile*

}

main.cpp:

#include <QtCore/QCoreApplication>

// This is the 'elder trick of the...' - Tell the compiler this function is defined in other place
extern "C"
void runCudaPart();

int main(int argc, char *argv[]) {

    QCoreApplication a(argc, argv);

    runCudaPart();

    return a.exec();

}

Here's the output of the error:

09:24:27: Running build steps for project first_project...
09:24:27: Configuration unchanged, skipping qmake step.
09:24:27: Starting: "/usr/bin/make" -w
make: Entering directory `/Users/lostsoul/Dropbox/qt_cuda/first_project-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Debug'
/usr/local/cuda/bin/nvcc -m64 -g -G -arch=compute_10 -c --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v -I/usr/local/cuda/include -I/Users/lostsoul/Dropbox/qt_cuda/C//common/inc/ -I/Users/lostsoul/Dropbox/qt_cuda/C//../shared/inc/ -lcudart -lcutil_x86_64 ../first_project/cuda_interface.cu -o ../first_project/Obj/cuda_interface_cuda.o
g++ -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++ -I../first_project -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include/QtGui -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include -I/usr/local/cuda/include -I../C/common/inc -I/Users/lostsoul/Dropbox/qt_cuda/C//../shared/inc/ -I. -I../first_project -I. -F/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/lib -o ../first_project/Obj/main.o ../first_project/main.cpp
gcc -c -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/mkspecs/macx-g++ -I../first_project -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtCore.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include/QtCore -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/lib/QtGui.framework/Versions/4/Headers -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include/QtGui -I../../../QtSDK/Desktop/Qt/4.8.1/gcc/include -I/usr/local/cuda/include -I../C/common/inc -I/Users/lostsoul/Dropbox/qt_cuda/C//../shared/inc/ -I. -I../first_project -I. -F/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/lib -o ../first_project/Obj/cuda_interface.o ../first_project/cuda_interface.cu
i686-apple-darwin11-llvm-gcc-4.2: ../first_project/cuda_interface.cu: linker input file unused because linking not done
g++ -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -o ../bin/first_project.app/Contents/MacOS/first_project ../first_project/Obj/cuda_interface_cuda.o ../first_project/Obj/main.o ../first_project/Obj/cuda_interface.o   -F/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/lib -L/usr/local/cuda/lib64 -L/Users/lostsoul/Dropbox/qt_cuda/C//lib -L/Users/lostsoul/Dropbox/qt_cuda/C//common/lib -L/Users/lostsoul/QtSDK/Desktop/Qt/4.8.1/gcc/lib -lcudart -lcutil_x86_64 -framework QtGui -L/usr/local/pgsql/lib -L/tmp/qt-stuff-85167/source/qt-everywhere-opensource-src-4.8.1/Desktop/Qt/4.8.1/gcc/lib -F/tmp/qt-stuff-85167/source/qt-everywhere-opensource-src-4.8.1/Desktop/Qt/4.8.1/gcc/lib -framework QtCore 
i686-apple-darwin11-llvm-g++-4.2: ../first_project/Obj/cuda_interface.o: No such file or directory
make: *** [../bin/first_project.app/Contents/MacOS/first_project] Error 1
make: Leaving directory `/Users/lostsoul/Dropbox/qt_cuda/first_project-build-desktop-Desktop_Qt_4_8_1_for_GCC__Qt_SDK__Debug'
09:24:33: The process "/usr/bin/make" exited with code 2.
Error while building project first_project (target: Desktop)
When executing build step 'Make'

I've been struggling to figure this out for the last few hours and I'm really unsure how to approach this. The only thing I thought was maybe my version of make was too new for the instructions(since the tutorial I followed was from last year) but commands seemed to execute. I'm really really new to C/Cuda and QT creator and my only goal is to execute c/c++ & cuda code on QT(because apparently it can compile both in a way they talk to each other and does code completion). The more I dig deep the more unsure I am if this error is a QT error or a C error(I don't think its a CUDA specific error since I really don't have any code there).

please help!

1条回答
仙女界的扛把子
2楼-- · 2019-05-26 14:51

Based on our discussion in the chat, we found a problem with the CUDA SDK installation directory, so you can simplify the .pro file by removing the SDK related stuff.

Check the blank space of your CUDA SDK installation directory (/Developer/GPU\ Computing/C) as it could be the cause of the problem.

Said that, the basic configuration that works using the latest software and osx lion is as follows:

QT += core
QT -= gui

TARGET = cuda_sample
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
# Source files for C/C++ compiler
SOURCES += main.cpp
# project build directories
DESTDIR = $$system(pwd)
OBJECTS_DIR = $$DESTDIR/Obj
# and C/C++ flags
QMAKE_CFLAGS_RELEASE =-O3
QMAKE_CXXFLAGS_RELEASE =-O3
# cuda source
CUDA_SOURCES += cuda_interface.cu
# Path to cuda toolkit install
CUDA_DIR = /usr/local/cuda
INCLUDEPATH += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib
# GPU architecture
CUDA_ARCH = sm_20
# NVCC flags
NVCCFLAGS = --compiler-options -fno-strict-aliasing -use_fast_math --ptxas-options=-v
# Path to libraries
LIBS += -lcudart -lcuda
# join the includes in a line
CUDA_INC = $$join(INCLUDEPATH,' -I','-I',' ')
# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
cuda.commands = $$CUDA_DIR/bin/nvcc -m64 -O3 -arch=$$CUDA_ARCH -c $$NVCCFLAGS $$CUDA_INC $$LIBS ${QMAKE_FILE_NAME} -o ${QMAKE_FILE_OUT}

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

cuda.input = CUDA_SOURCES
cuda.output = ${OBJECTS_DIR}${QMAKE_FILE_BASE}_cuda.o
# Tell Qt that we want add more stuff to the Makefile
QMAKE_EXTRA_COMPILERS += cuda

As we are not using the CUDA SDK libs, remove from your cuda_interface.cu file the following line

#include <cutil_inline.h> // remove this line from your file

That's all. Remember run qmake to take the changes of the .pro file.

查看更多
登录 后发表回答