我有一个用Qt(Win32,VS2010)和CUDA编写的项目,我的cu文件包含Qt头文件。当我尝试用新的Qt 5.0构建我的项目时(Qt 4.8.3没问题),我遇到了以下错误:
C:/Qt/Qt5.0.0/5.0.0/msvc2010/include\QtCore/qobject_impl.h(82): error: too many initializer values
C:/Qt/Qt5.0.0/5.0.0/msvc2010/include\QtCore/qobject_impl.h(85): error: too many initializer values
C:/Qt/Qt5.0.0/5.0.0/msvc2010/include\QtCore/qobject_impl.h(89): error: too many initializer values
我创建了一个简单的项目来重现该错误并将其复制。我相信任何使用Qt标头的CUDA的Qt项目都可以重复它。但是,我添加了简单的代码来重现下面的错误。任何人都可以帮助我吗?
test1.pro文件:
QT += core
QT -= gui
TARGET = qt_cuda_test
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
OTHER_FILES += \
kernel.cu
INCLUDEPATH += $$quote($$(CUDA_INC_PATH))
CUDA_SOURCES += kernel.cu
CUDA_SDK = "C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 5.0/C" # Path to cuda SDK install
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0" # Path to cuda toolkit install
SYSTEM_NAME = Win32 # Depending on your system either 'Win32', 'x64', or 'Win64'
SYSTEM_TYPE = 32 # '32' or '64', depending on your system
CUDA_ARCH = sm_20 # Type of CUDA architecture, for example 'compute_10', 'compute_11', 'sm_10'
NVCC_OPTIONS = --use_fast_math
# include paths
INCLUDEPATH += $$CUDA_DIR/include \
$$CUDA_SDK/common/inc/ \
$$CUDA_SDK/../shared/inc/ \
# library directories
QMAKE_LIBDIR += $$CUDA_DIR/lib/$$SYSTEM_NAME \
$$CUDA_SDK/common/lib/$$SYSTEM_NAME \
$$CUDA_SDK/../shared/lib/$$SYSTEM_NAME
# Add the necessary libraries
LIBS += -lcuda -lcudart
# The following library conflicts with something in Cuda
QMAKE_LFLAGS_RELEASE = /NODEFAULTLIB:msvcrt.lib
# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')
# Configuration of the Cuda compiler
cuda.input = CUDA_SOURCES
cuda.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC -I"C:/Qt/Qt5.0.0/5.0.0/msvc2010/include" $$LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS += cuda
kernel.cu文件:
#include <QtCore/QCoreApplication>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
cudaError_t addWithCuda(int *c, const int *a, const int *b, size_t size);
__global__ void addKernel(int *c, const int *a, const int *b)
{
int i = threadIdx.x;
c[i] = a[i] + b[i];
}
int main()
{
const int arraySize = 5;
const int a[arraySize] = { 1, 2, 3, 4, 5 };
const int b[arraySize] = { 10, 20, 30, 40, 50 };
int c[arraySize] = { 0 };
cudaError_t cudaStatus = addWithCuda(c, a, b, arraySize);
return 0;
}
// do something with cuda
cudaError_t addWithCuda(int *c, const int *a, const int *b, size_t size)
{
int *dev_a = 0;
int *dev_b = 0;
int *dev_c = 0;
cudaError_t cudaStatus;
}