在发生许多模糊错误(至少对我来说)之后,我发现在尝试设置QtCreator项目文件以便与CUDA一起使用时,在Makefile.Debug和Makefile的LIBS定义中放置了一些额外的引号。发布文件。
LIBS = /LIBPATH:"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\lib\x64" ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\lib\x64"\cuda.lib" ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.0\lib\x64"\cudart.lib" /LIBPATH:C:\Qt\5.2.1\msvc2012_64_opengl\lib C:\Qt\5.2.1\msvc2012_64_opengl\lib\Qt5Cored.lib
如果仔细观察LIBPATH中的第二个条目,您会在C:前面看到一个额外的引号。您还会在x64之后的字符串中间看到一个额外的引号。对于CUDA库的两个条目都会发生此异常。如果我进入这个makefile并手动更正它(删除额外的引号),项目构建并运行没有错误。
所以,我想知道如何设置项目文件来纠正这个问题。它已经老了,不得不回到makefile进行手动修复。
供参考,这是我的整个项目文件。
QT += core
QT -= gui
TARGET = QtCuda
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
HEADERS += cuda/vectorAddition.h
#OTHER_FILES += cuda_code.cu
# project build directories
CONFIG(debug, debug|release) {
# Debug mode
DESTDIR = $$PWD/debug
}
else {
# Release mode
DESTDIR = $$PWD/release
}
OBJECTS_DIR = $$DESTDIR/obj
# Cuda sources
CUDA_SOURCES += cuda/vectorAddition.cu
# Path to cuda toolkit install
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v7.0"
# Path to header and libs files
INCLUDEPATH += $$CUDA_DIR/include
QMAKE_LIBDIR += $$CUDA_DIR/lib/x64
# '32' or '64', depending on your system
SYSTEM_TYPE = 64
# libs used in your code
LIBS += -lcuda -lcudart
# GPU architecture
CUDA_ARCH = sm_50
# Here are some NVCC flags I've always used by default.
NVCCFLAGS = --use_fast_math
# Prepare the extra compiler configuration (taken from the nvidia forum - i'm not an expert in this part)
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
# MSVCRT link option (static or dynamic, it must be the same with your Qt SDK link option)
MSVCRT_LINK_FLAG_DEBUG = "/MDd"
MSVCRT_LINK_FLAG_RELEASE = "/MD"
# Configuration of the Cuda compiler
CONFIG(debug, debug|release) {
# Debug mode
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$OBJECTS_DIR/${QMAKE_FILE_BASE}.obj
cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS --machine $$SYSTEM_TYPE \
-arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME} -Xcompiler $$MSVCRT_LINK_FLAG_DEBUG
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
# Release mode
cuda.input = CUDA_SOURCES
cuda.output = $$OBJECTS_DIR/${QMAKE_FILE_BASE}.obj
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS --machine $$SYSTEM_TYPE \
-arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME} -Xcompiler $$MSVCRT_LINK_FLAG_RELEASE
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
}
HEADERS += \
cuda/vectorAddition.h
答案 0 :(得分:2)
如果库路径中至少有一个空格,则会在Qt 5.3.0
,Qt 5.3.2
上复制该错误。它与Qt 5.5.1
一样正常工作。
所以,有两种选择:
5.5.1
(某些早期版本也可以使用);