编译cuda文件错误:“运行时库”不匹配值“MDd_DynamicDebug”与vectorAddition_cuda.o中的值“MTd_StaticDebug”不匹配 [英] Compile cuda file error: "runtime library" mismatch value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda.o

查看:2754
本文介绍了编译cuda文件错误:“运行时库”不匹配值“MDd_DynamicDebug”与vectorAddition_cuda.o中的值“MTd_StaticDebug”不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Qt 5.2和MSVC2012环境中编译一个cuda文件。
在开始我的项目之前,我仔细阅读了这个问题,并回答:在Windows上的Qt Creator中编译Cuda代码
但是仍然有一些错误弹出,即使我只是复制代码,并在qt中生成2个文件

  main.cpp 
/vectorAddition.cu

错误是:



错误LNK2038:为RuntimeLibrary检测到不匹配:值MDd_DynamicDebug与vectorAddition_cuda.o中的值MTd_StaticDebug不匹配

我完全不知道如何修复这个bug。我在线阅读了一些关于修复MSVC2012不匹配的文章。但是很少有人提到如何在Qt .pro文件中做。任何一个碰巧有这个问题吗?



我还在这里附加了pro文件(根据我自己的目录进行了细微修改)

 #------------------------------------------- ------ 

#由QtCreator创建的项目2014-10-05T13:22:19

#----------- --------------------------------------

QT + = core gui

greaterThan(QT_MAJOR_VERSION,4):QT + = widgets

TARGET = untitled
TEMPLATE = app


SOURCES + = main.cpp

HEADERS + = mainwindow.h

FORMS + = mainwindow.ui


#定义输出目录
DESTDIR = debug
OBJECTS_DIR = debug / obj
CUDA_OBJECTS_DIR = debug / obj

#源文件

#这使得.cu文件出现在您的项目中
OTHER_FILES + = vectorAddition.cu

#CUDA设置< - 可能会根据您的系统而有所不同
CUDA_SOURCES + = vectorAddition.cu
CUDA_SDK =C:/ ProgramData / NVIDIA公司/ NVIDIA GPU计算SDK 4.0 / C#路径到cuda SDK安装
CUDA_DIR =C:\Program Files \NVIDIA GPU计算工具包\CUDA \v6 .5#路径到cuda工具包安装
SYSTEM_NAME = Win32#根据您的系统'Win32','x64'或'Win64'
SYSTEM_TYPE = 32#'32'或'64'取决于您的系统
CUDA_ARCH = sm_30#CUDA体系结构的类型,例如'compute_10','compute_11','sm_10'
NVCC_OPTIONS = --use_fast_math

#include路径
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 /../共享/ lib / $$ SYSTEM_NAME
#添加必要的库
LIBS + = -lcuda -lcudart
#MSVCRT链接选项(静态或动态,它必须与Qt SDK链接相同选项)
MSVCRT_LINK_FLAG_DEBUG =/ MDd
MSVCRT_LINK_FLAG_RELEASE =/ MD

#以下内容确保所有路径名(通常包含空格) b $ b CUDA_INC = $$ join(INCLUDEPATH,'-I',' - I','')

#配置Cuda编译器
CONFIG debug | release){
#调试模式
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$ CUDA_OBJECTS_DIR / $ {QMAKE_FILE_BASE} _cuda.o
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}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS + = cuda_d
}
else {
#发布模式
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 $$ LIBS --machine $$ SYSTEM_TYPE -arch = $$ CUDA_ARCH -c -o $ {QMAKE_FILE_OUT } $ {QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS + = cuda
}


b $ b

这里是我的日志

  13:58:14: b $ b 13:58:14:配置不变,跳过qmake步骤。 
13:58:14:开始:C:\Qt\Qt5.2.0\Tools\QtCreator\bin\jom.exe
C:\Qt\Qt5 .2.0 \Tools\QtCreator\bin\jom.exe -f Makefile.Debug
C:\Program Files\ NVIDIA GPU计算工具包\CUDA\v6.5\bin\\ \\ nvcc.exe-D_DEBUG --use_fast_math -IC:\Program Files \ NVIDIA GPU计算工具包\CUDA \v6.5 / include-IC:/ ProgramData / NVIDIA公司/ NVIDIA GPU计算SDK 4.0 / C / common / inc /-IC:/ ProgramData / NVIDIA公司/ NVIDIA GPU计算SDK 4.0 / C /../ shared / inc /-lcuda -lcudart --machine 32 -arch = sm_30 - c -o debug\obj\vectorAddition_cuda.obj .. \untitled\vectorAddition.cu
vectorAddition.cu
echo 1 / * CREATEPROCESS_MANIFEST_RESOURCE_ID * / 24 / * RT_MANIFEST * /debug\ \untitled.exe.embed.manifest> debug\ititled.exe_manifest.rc
(如果不存在)debug\untitled.exe(如果存在)debug\untitled.exe.embed.manifest del debug\untitled .exe.embed.manifest
如果存在debug\untitled.exe.embed.manifest copy / Y debug\untitled.exe.embed.manifest debug\untitled.exe_manifest.bak
link / NOLOGO / DYNAMICBASE / NXCOMPAT /NODEFAULTLIB:msvcrtd.lib / SUBSYSTEM:WINDOWS/ MANIFESTDEPENDENCY:type ='win32'name ='Microsoft.Windows.Common-Controls'version ='6.0.0.0'publicKeyToken ='6595b64144ccf1df'language = 'processorArchitecture ='*'/ MANIFEST /MANIFESTFILE:debug\untitled.exe.embed.manifest /OUT:debug\untitled.exe @C:\Users\JYOU\AppData\Local\Temp\\ \\untitled.exe.4748.3744.jom
main.obj:error LNK2038:为RuntimeLibrary检测到不匹配:值MDd_DynamicDebug与vectorAddition_cuda.obj中的值MTd_StaticDebug不匹配
moc_mainwindow.obj:错误LNK2038:检测到RuntimeLibrary的不匹配:值MDd_DynamicDebug与vectorAddition_cuda.obj中的值MTd_StaticDebug不匹配
LINK:致命错误LNK1181:无法打开输入文件'C:\Program.obj'
jom:C:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-untitled-Desktop_Qt_5_2_0_MSVC2012_32bit-Debug\Makefile.Debug [debug\untitled.exe]错误1181
jom:C:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-untitled-Desktop_Qt_5_2_0_MSVC2012_32bit-Debug \Makefile [debug]错误2
13:58:18:使用代码2退出过程C:\ Qt\Qt5.2.0\Tools\QtCreator\bin\jom.exe。
在构建/部署项目时出错(未命名)(kit:Desktop Qt 5.2 .0 MSVC2012 32bit)
执行步骤'Make'
13:58:18:经过时间:00:04。

问题重复的说明



我还阅读了文章检测到的RuntimeLibraryCrypto ++ Mismatch < a>
但是区别是我的问题是关于NVCC设置在Qt这是比MSVC环境更复杂。即使/ MDd由下面的代码设置,没有正确的NVCC设置,cu文件仍然无法编译。简单的更改运行时库并没有完全解决我的问题。这是NVCC的设置最终做到的。

 #MSVCRT链接选项(静态或动态,它必须与您的Qt SDK链接选项相同)
MSVCRT_LINK_FLAG_DEBUG =/ MDd
MSVCRT_LINK_FLAG_RELEASE =/ MD


我通过阅读其他文章解决了我的问题
http:// robot9.me/cuda_qtcreator_windows/



作为问题 Crypto ++ Mismatch检测为'RuntimeLibrary'建议。 MSVCRT链接选项需要保持一致。因此,在$ NVCC配置之前添加 / MDd 设置。



但是关键是设置 cuda.commands 。与问题不同:在Windows上在Qt Creator中编译Cuda代码 (我试过配置,但不适用于我)
我的nvcc设置如下:

 #MSVCRT链接选项(静态或动态,它必须与您的Qt SDK链接选项相同)
MSVCRT_LINK_FLAG_DEBUG =/ MDd
MSVCRT_LINK_FLAG_RELEASE =/ MD

CONFIG debug | release){
#Debug设置
#调试模式
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$ CUDA_OBJECTS_DIR / $ {QMAKE_FILE_BASE} _cuda.obj
cuda_d.commands = $$ CUDA_DIR / bin / nvcc.exe -D_DEBUG $$ NVCC_OPTIONS $$ CUDA_INC $$ LIBS \
--machine $$ SYSTEM_TYPE -arch = $$ CUDA_ARCH \
- -compile -cudart static -g -DWIN32 -D_MBCS \
-Xcompiler/ wd4819,/ EHsc,/ W3,/ nologo,/ Od,/ Zi,/ RTC1\
-Xcompiler $ $ MSVCRT_LINK_FLAG_DEBUG \
-c -o $ {QMAKE_FILE_OUT} $ {QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS + = cuda_d
}
else {
#释放设置
cuda.input = CUDA_SOURCES
cuda.output = $$ CUDA_OBJECTS_DIR / $ {QMAKE_FILE_BASE} _cuda.obj
cuda.commands = $$ CUDA_DIR / bin / nvcc.exe $$ NVCC_OPTIONS $$ CUDA_INC $$ LIBS \
--machine $$ SYSTEM_TYPE -arch = $$ CUDA_ARCH \
--compile -cudart static -DWIN32 -D_MBCS \
- Xcompiler/ wd4819,/ EHsc,/ W3,/ nologo,/ O2,/ Zi\
-Xcompiler $$ MSVCRT_LINK_FLAG_RELEASE \
-c -o $ {QMAKE_FILE_OUT} $ {QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS + = cuda
}

即使我还是不完全理解一些cuda.commands,但它真的有效。
请参阅 http:// docs。 nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#axzz3FOBrgXpc 了解NVCC配置的更多详细信息。



这是我的.pro文件的完整版本

  ------------------------------------------------- 

#由QtCreator创建的项目2013-09-01T16:29:35

#------------------ -------------------------------

QT + = core gui

greaterThan(QT_MAJOR_VERSION,4):QT + =小部件

TARGET = FFTW //您的项目名称
TEMPLATE = app

HEADERS + = dialog.h \
include / fftw3.h \ // header我需要我的项目


SOURCES + = main.cpp \
dialog.cpp


INCLUDEPATH + = $$ PWD /
DEPENDPATH + = $$ PWD /

DESTDIR = debug
OBJECTS_DIR = debug / obj#directory其中.obj文件将被保存
CUDA_OBJECTS_DIR = debug / obj#目录其中.obj的cuda文件将被保存
#这使得.cu文件出现在您的项目中

OTHER_FILES + = intmapping.cu#这是我的cu文件需要编译

#CUDA设置< - 可能会根据您的系统更改

CUDA_SOURCES + = intmapping.cu #let NVCC知道你要编译哪个文件CUDA NVCC

CUDA_SDK =C:\ProgramData\NVIDIA公司\ NVIDIA GPU计算SDK 4.0 \C#路径cuda SDK安装
CUDA_DIR =C:/ Program Files / NVIDIA GPU计算工具包/ CUDA / v6.5
SYSTEM_NAME = Win32#根据您的系统'Win32','x64'或'Win64'
SYSTEM_TYPE = 32#'32'或'64',具体取决于您的系统
CUDA_ARCH = sm_20#CUDA体系结构的类型,例如'compute_10','compute_11','sm_10'
NVCC_OPTIONS + = --use_fast_math#default setting

#include paths

INCLUDEPATH + = $$ CUDA_DIR / include\
$$ CUDA_SDK / common / inc\
$$ CUDA_SDK /../ shared / inc\


#库目录
QMAKE_LIBDIR + = $$ join(CUDA_DIR,'-I '-I','')/ common / lib / $$ $$ SYSTEM_NAME\
$$ join(CUDA_SDK,'-I',' - I','')/../ shared / lib / $$ SYSTEM_NAME

#添加必要的库
CUDA_LIBS = -lcuda -lcudart -lcufft
#add这些目录的引号包含空格(需要Windows)
CUDA_INC + = $$ join(INCLUDEPATH,'
#nvcc config
#MSVCRT链接选项(静态或动态,必须与您的Qt SDK链接选项相同)
MSVCRT_LINK_FLAG_DEBUG =/ MDd
MSVCRT_LINK_FLAG_RELEASE =/ MD

CONFIG(debug,debug | release){
#Debug设置
#调试模式
cuda_d.input = CUDA_SOURCES
cuda_d.output = $$ CUDA_OBJECTS_DIR / $ {QMAKE_FILE_BASE} _cuda.obj
cuda_d.commands = $$ CUDA_DIR /bin/nvcc.exe -D_DEBUG $$ NVCC_OPTIONS $$ CUDA_INC $$ LIBS \
--machine $$ SYSTEM_TYPE -arch = $$ CUDA_ARCH \
--compile -cudart static -g - DWIN32 -D_MBCS \
-Xcompiler/ wd4819,/ EHsc,/ W3,/ nologo,/ Od,/ Zi,/ RTC1\
-Xcompiler $$ MSVCRT_LINK_FLAG_DEBUG \
-c -o $ {QMAKE_FILE_OUT} $ {QMAKE_FILE_NAME}
cuda_d.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS + = cuda_d
}
else {
#发布设置
cuda.input = CUDA_SOURCES
cuda.output = $$ CUDA_OBJECTS_DIR / $ {QMAKE_FILE_BASE} _cuda.obj
cuda.commands = $$ CUDA_DIR / bin / nvcc.exe $$ NVCC_OPTIONS $$ CUDA_INC $$ LIBS \
--machine $$ SYSTEM_TYPE -arch = $$ CUDA_ARCH \
--compile -cudart static -DWIN32 -D_MBCS \
-Xcompiler/ wd4819,/ EHsc, / W3,/ nologo,/ O2,/ Zi\
-Xcompiler $$ MSVCRT_LINK_FLAG_RELEASE \
-c -o $ {QMAKE_FILE_OUT} $ {QMAKE_FILE_NAME}
cuda.dependency_type = TYPE_C
QMAKE_EXTRA_COMPILERS + = cuda
}

FORMS + = \
dialog.ui

win32:LIBS + = -L $$ PWD / lib / -llibfftw3f-3 #library我需要在我的项目

INCLUDEPATH + = $$ PWD / lib
DEPENDPATH + = $$ PWD / lib


I tried to compile a cuda file in Qt 5.2 and MSVC2012 environment. Before I started my project, I carefully read the question and reply in :Compiling Cuda code in Qt Creator on Windows. But there are still some errors popping out even though I simply copied the code and generated 2 files in qt

/main.cpp
/vectorAddition.cu

the error is :

error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda.o

I just totally have no idea how to fix this bug. I read some article online about fixing the mismatch in MSVC2012. But few of them mentioned how to do it in Qt .pro file. Does any one happen to have this problem?

I also attached the pro file here (with minor modified according to my own directory)

#-------------------------------------------------
#
# Project created by QtCreator 2014-10-05T13:22:19
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = untitled
TEMPLATE = app


SOURCES += main.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui


# Define output directories
DESTDIR = debug
OBJECTS_DIR = debug/obj
CUDA_OBJECTS_DIR = debug/obj

# Source files

# This makes the .cu files appear in your project
OTHER_FILES += vectorAddition.cu

# CUDA settings <-- may change depending on your system
CUDA_SOURCES += vectorAddition.cu
CUDA_SDK = "C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C"   # Path to cuda SDK install
CUDA_DIR = "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5"            # 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_30           # 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
# 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"

# 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
CONFIG(debug, debug|release) {
    # Debug mode
    cuda_d.input = CUDA_SOURCES
    cuda_d.output = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.o
    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}
    cuda_d.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
    # Release mode
    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 $$LIBS --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
    cuda.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda
}

And here is my log

13:58:14: Running steps for project untitled...
13:58:14: Configuration unchanged, skipping qmake step.
13:58:14: Starting: "C:\Qt\Qt5.2.0\Tools\QtCreator\bin\jom.exe" 
    C:\Qt\Qt5.2.0\Tools\QtCreator\bin\jom.exe -f Makefile.Debug
    "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5\bin\nvcc.exe" -D_DEBUG --use_fast_math -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.5/include" -I"C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C/common/inc/" -I"C:/ProgramData/NVIDIA Corporation/NVIDIA GPU Computing SDK 4.0/C/../shared/inc/" -lcuda -lcudart --machine 32 -arch=sm_30 -c -o debug\obj\vectorAddition_cuda.obj ..\untitled\vectorAddition.cu
vectorAddition.cu
    echo 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "debug\\untitled.exe.embed.manifest">debug\untitled.exe_manifest.rc
    if not exist debug\untitled.exe if exist debug\untitled.exe.embed.manifest del debug\untitled.exe.embed.manifest
    if exist debug\untitled.exe.embed.manifest copy /Y debug\untitled.exe.embed.manifest debug\untitled.exe_manifest.bak
    link /NOLOGO /DYNAMICBASE /NXCOMPAT /NODEFAULTLIB:msvcrtd.lib /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST /MANIFESTFILE:debug\untitled.exe.embed.manifest /OUT:debug\untitled.exe @C:\Users\JYOU\AppData\Local\Temp\untitled.exe.4748.3744.jom
main.obj : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda.obj
moc_mainwindow.obj : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value 'MTd_StaticDebug' in vectorAddition_cuda.obj
LINK : fatal error LNK1181: cannot open input file 'C:\Program.obj'
jom: C:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-untitled-Desktop_Qt_5_2_0_MSVC2012_32bit-Debug\Makefile.Debug [debug\untitled.exe] Error 1181
jom: C:\Qt\Qt5.2.0\Tools\QtCreator\bin\build-untitled-Desktop_Qt_5_2_0_MSVC2012_32bit-Debug\Makefile [debug] Error 2
13:58:18: The process "C:\Qt\Qt5.2.0\Tools\QtCreator\bin\jom.exe" exited with code 2.
Error while building/deploying project untitled (kit: Desktop Qt 5.2.0 MSVC2012 32bit)
When executing step 'Make'
13:58:18: Elapsed time: 00:04.

Explanation for "question duplication":

I also read the article Crypto++ Mismatch Detected for 'RuntimeLibrary' But the difference is that my question is about NVCC set up in Qt which is more complex than in MSVC environment. Even though /MDd is set by the following code, without the correct setting of NVCC, cu file still not able to compile. Simple change of runtime library did not totally solve my question. It is the setting of NVCC eventually made it.

# 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"

解决方案

I got my question solved by reading another article http://robot9.me/cuda_qtcreator_windows/

As the question Crypto++ Mismatch Detected for 'RuntimeLibrary' suggested. MSVCRT link option needs to keep consistent. So the /MDd setting is added before NVCC config.

But the key is to set cuda.commands correctly. Different from question: Compiling Cuda code in Qt Creator on Windows (i tried that config but does not work for me) my nvcc is set like this:

   # 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"

   CONFIG(debug, debug|release) {
    #Debug settings
    # Debug mode
    cuda_d.input    = CUDA_SOURCES
    cuda_d.output   = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj
    cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS \
                      --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
                      --compile -cudart static -g -DWIN32 -D_MBCS \
                      -Xcompiler "/wd4819,/EHsc,/W3,/nologo,/Od,/Zi,/RTC1" \
                      -Xcompiler $$MSVCRT_LINK_FLAG_DEBUG \
                      -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
    cuda_d.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
     # Release settings
     cuda.input    = CUDA_SOURCES
     cuda.output   = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj
     cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS \
                    --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
                    --compile -cudart static -DWIN32 -D_MBCS \
                    -Xcompiler "/wd4819,/EHsc,/W3,/nologo,/O2,/Zi" \
                    -Xcompiler $$MSVCRT_LINK_FLAG_RELEASE \
                    -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
     cuda.dependency_type = TYPE_C
     QMAKE_EXTRA_COMPILERS += cuda
}

Even though I still do not fully understand some of cuda.commands, but it really works. Please refer to http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#axzz3FOBrgXpc for more detail of NVCC config.

Here is the full version of my .pro file

#-------------------------------------------------
#
# Project created by QtCreator 2013-09-01T16:29:35
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = FFTW //your project name
TEMPLATE = app

HEADERS  += dialog.h \
    include/fftw3.h \   //header i need for my project 


SOURCES += main.cpp\
           dialog.cpp


INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/

DESTDIR = debug           
OBJECTS_DIR = debug/obj           # directory where .obj files will be saved
CUDA_OBJECTS_DIR = debug/obj      # directory where .obj  of cuda file will be saved
# This makes the .cu files appear in your project

OTHER_FILES += intmapping.cu      # this is my cu file need to compile

# CUDA settings <-- may change depending on your system

CUDA_SOURCES += intmapping.cu     # let NVCC know which file you want to compile CUDA NVCC

CUDA_SDK = "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C"   # Path to cuda SDK install
CUDA_DIR = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v6.5"
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 # default setting

# include paths

INCLUDEPATH += $$CUDA_DIR/include\
                $$CUDA_SDK/common/inc\
                $$CUDA_SDK/../shared/inc\


# library directories
QMAKE_LIBDIR += $$join(CUDA_DIR,'" -I"','-I"','"')/lib/$$SYSTEM_NAME\
                $$join(CUDA_SDK,'" -I"','-I"','"')/common/lib/$$SYSTEM_NAME\
                $$join(CUDA_SDK,'" -I"','-I"','"')/../shared/lib/$$SYSTEM_NAME

# Add the necessary libraries
CUDA_LIBS= -lcuda -lcudart -lcufft
#add quotation for those directories contain space (Windows required)
CUDA_INC +=$$join(INCLUDEPATH,'" -I"','-I"','"')

LIBS += $$CUDA_LIBS
#nvcc config
# 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"

CONFIG(debug, debug|release) {
    #Debug settings
    # Debug mode
    cuda_d.input    = CUDA_SOURCES
    cuda_d.output   = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj
    cuda_d.commands = $$CUDA_DIR/bin/nvcc.exe -D_DEBUG $$NVCC_OPTIONS $$CUDA_INC $$LIBS \
                      --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
                      --compile -cudart static -g -DWIN32 -D_MBCS \
                      -Xcompiler "/wd4819,/EHsc,/W3,/nologo,/Od,/Zi,/RTC1" \
                      -Xcompiler $$MSVCRT_LINK_FLAG_DEBUG \
                      -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
    cuda_d.dependency_type = TYPE_C
    QMAKE_EXTRA_COMPILERS += cuda_d
}
else {
     # Release settings
     cuda.input    = CUDA_SOURCES
     cuda.output   = $$CUDA_OBJECTS_DIR/${QMAKE_FILE_BASE}_cuda.obj
     cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBS \
                    --machine $$SYSTEM_TYPE -arch=$$CUDA_ARCH \
                    --compile -cudart static -DWIN32 -D_MBCS \
                    -Xcompiler "/wd4819,/EHsc,/W3,/nologo,/O2,/Zi" \
                    -Xcompiler $$MSVCRT_LINK_FLAG_RELEASE \
                    -c -o ${QMAKE_FILE_OUT} ${QMAKE_FILE_NAME}
     cuda.dependency_type = TYPE_C
     QMAKE_EXTRA_COMPILERS += cuda
}

FORMS += \
     dialog.ui

win32: LIBS += -L$$PWD/lib/ -llibfftw3f-3 #library i need in my project

INCLUDEPATH += $$PWD/lib
DEPENDPATH += $$PWD/lib

这篇关于编译cuda文件错误:“运行时库”不匹配值“MDd_DynamicDebug”与vectorAddition_cuda.o中的值“MTd_StaticDebug”不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆