我正在尝试使用 QT creator 作为 IDE 开始使用 C 和 Cuda。不幸的是,我从一开始就遇到了问题,并且不确定它来自哪里(如果它是逐渐开始的,那就更容易识别了)。
我基本上已经安装了 CUDA(和 c)并运行了小型测试程序,但我想使用 IDE,所以我使用以下说明安装了 QT creator:http: //cudaspace.wordpress.com/2011/04/07/qt- creator-cuda-linux/ 但在运行示例时出现错误:'链接器输入文件未使用,因为链接未完成'
这是所有文件(由于我使用的是mac并且说明适用于linux,因此我进行了修改。我可以编译基本hello world
类型的东西,但由于某种原因不能编译示例):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*
}
主.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();
}
这是错误的输出:
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'
在过去的几个小时里,我一直在努力解决这个问题,我真的不确定如何解决这个问题。我唯一想到的可能是我的 make 版本对于指令来说太新了(因为我遵循的教程是去年的),但命令似乎可以执行。我对 C/Cuda 和 QT 创建者真的很陌生,我唯一的目标是在 QT 上执行 c/c++ 和 cuda 代码(因为显然它可以以它们相互对话的方式编译并完成代码完成)。我越深入越不确定这个错误是 QT 错误还是 C 错误(我不认为它是 CUDA 特定的错误,因为我真的没有任何代码)。
请帮忙!