Qtcreator , windows and cuda

Hello,

I try to setup my Qtcreator project with cuda on Windows.
Here is my pro file:

# This makes the .cu files appear in your project
SOURCES += \
    src/main.cpp #\



# CUDA settings <-- may change depending on your system
CUDA_SOURCES += ./cuda/Blending.cu
CUDA_SOURCES += ./cuda/CCL.cu


INCLUDEPATH += C:\opencv\build\include
INCLUDEPATH += C:\opencv\build\include\opencv

#LIBS+= -LC:\\opencv\\build\\x86\\vc12\\lib
#LIBS+=libopencv_core24134
#LIBS+=libopencv_imgproc2413
#LIBS+=libopencv_highgui2413
#LIBS+=libopencv_objdetect2413
#LIBS+=libopencv_calib3d2413

LIBS+=C:\opencv\build\x86\vc12\lib\opencv_core2413.lib
LIBS+=C:\opencv\build\x86\vc12\lib\opencv_imgproc2413.lib
LIBS+=C:\opencv\build\x86\vc12\lib\opencv_highgui2413.lib
LIBS+=C:\opencv\build\x86\vc12\lib\opencv_objdetect2413.lib
LIBS+=C:\opencv\build\x86\vc12\lib\opencv_calib3d2413.lib

LIBSCUDA += -LC:\opencv\build\x86\vc12\lib
LIBSCUDA += -lopencv_core2413
LIBSCUDA += -lopencv_imgproc2413
LIBSCUDA += -lopencv_highgui2413
LIBSCUDA += -lopencv_objdetect2413
LIBSCUDA += -lopencv_calib3d2413


CUDA_SDK = "C:/ProgramData/NVIDIA Corporation/CUDA Samples/v8.0"#"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\v8.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 = compute_50           # 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 = "/FS"

# The following makes sure all path names (which often include spaces) are put between quotation marks
CUDA_INC = $$join(INCLUDEPATH,'" -I"','-I"','"')


     cuda.input    = CUDA_SOURCES
     cuda.output   = ${QMAKE_FILE_BASE}_cuda.o
     cuda.commands = $$CUDA_DIR/bin/nvcc.exe $$NVCC_OPTIONS $$CUDA_INC $$LIBSCUDA \
                    --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



HEADERS += \

    cuda/Blending.h# \

When I try to compile a single cuda file and cpp with MSVCRT_LINK_FLAG_RELEASE = "/MD"n the compilation works. But when I want to use multiple cu file and when I change MSVCRT_LINK_FLAG_RELEASE = “/FS” there is these errors:

C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Release
	link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:release\untitled.exe @C:\Users\SENIOR~1\AppData\Local\Temp\untitled.exe.5196.0.jom
main.obj : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "bool __cdecl std::uncaught_exception(void)" (?uncaught_exception@std@@YA_NXZ) already defined in libcpmt.lib(uncaught.obj)
msvcprt.lib(MSVCP140.dll) : error LNK2005: "void __cdecl std::_Xbad_alloc(void)" (?_Xbad_alloc@std@@YAXXZ) already defined in libcpmt.lib(xthrow.obj)
msvcprt.lib(MSVCP140.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
msvcprt.lib(MSVCP140.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmt.lib(xthrow.obj)
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputc(char)" (?sputc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHD@Z) already defined in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: __int64 __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,__int64)" (?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAE_JPBD_J@Z) already defined in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: void __thiscall std::basic_ios<char,struct std::char_traits<char> >::setstate(int,bool)" (?setstate@?$basic_ios@DU?$char_traits@D@std@@@std@@QAEXH_N@Z) already defined in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" (?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ) already defined in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(bool)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@_N@Z) already defined in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(int)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z) already defined in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(unsigned int)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@I@Z) already defined in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(float)" (??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@M@Z) already defined in Blending_cuda.o
msvcprt.lib(MSVCP140.dll) : error LNK2005: "public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" (?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ) already defined in Blending_cuda.o
qtmain.lib(qtmain_win.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in Blending_cuda.o
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
main.obj : warning LNK4217: locally defined symbol __invalid_parameter_noinfo_noreturn imported in function "void __cdecl std::_Deallocate(void *,unsigned int,unsigned int)" (?_Deallocate@std@@YAXPAXII@Z)
main.obj : warning LNK4217: locally defined symbol _memmove imported in function "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > & __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::erase(unsigned int,unsigned int)" (?erase@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAEAAV12@II@Z)
Blending_cuda.o : error LNK2019: unresolved external symbol ___cudaRegisterLinkedBinary_44_tmpxft_00002368_00000000_11_Blending_cpp1_ii_38dfa19b referenced in function "void __cdecl __sti____cudaRegisterAll_44_tmpxft_00002368_00000000_11_Blending_cpp1_ii_38dfa19b(void)" (?__sti____cudaRegisterAll_44_tmpxft_00002368_00000000_11_Blending_cpp1_ii_38dfa19b@@YAXXZ)
CCL_cuda.o : error LNK2019: unresolved external symbol ___cudaRegisterLinkedBinary_39_tmpxft_00001170_00000000_11_CCL_cpp1_ii_6461764f referenced in function "void __cdecl __sti____cudaRegisterAll_39_tmpxft_00001170_00000000_11_CCL_cpp1_ii_6461764f(void)" (?__sti____cudaRegisterAll_39_tmpxft_00001170_00000000_11_CCL_cpp1_ii_6461764f@@YAXXZ)
MSVCRT.lib(_chandler4gs_.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
release\untitled.exe : fatal error LNK1120: 3 unresolved externals
jom: C:\Users\seniordev\Desktop\Developpement\Cuda\build-CudaWindows-Desktop_Qt_5_6_2_MSVC2015_32bit2-Release\Makefile.Release [release\untitled.exe] Error 1120

I don’t understand why this append. I use on MSVC 15 32bit version compiler.

I finally add improvments but the compilation don’t work…

So my problem comes from the extra compiler on QtCreator. Now I try to link all cuda file into a on global file.

I try that command:

"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0/bin/nvcc.exe" -ccbin g++ -dlink --use_fast_math -I"C:\opencv\build\include" -I"C:\opencv\build\include\opencv" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0/include" -I"C:/ProgramData/NVIDIA Corporation/CUDA Samples/v8.0/common/inc/" -I"C:/ProgramData/NVIDIA Corporation/CUDA Samples/v8.0/../shared/inc/" C:\opencv\build\x86\vc12\lib\opencv_core2413.lib C:\opencv\build\x86\vc12\lib\opencv_imgproc2413.lib C:\opencv\build\x86\vc12\lib\opencv_highgui2413.lib C:\opencv\build\x86\vc12\lib\opencv_objdetect2413.lib C:\opencv\build\x86\vc12\lib\opencv_calib3d2413.lib -lcuda -lcudart --machine 32 -arch=compute_50 Blending_cuda.o CCL_cuda.o -o release/obj/untitled.obj

There is no error but no file is generated .
How can this be possible?

Please I am really stuck.
I still try to link my cpp and cu files but I have no solution.

You can’t use:

-ccbin g++

on windows

And when you specify:

-dlink

You are asking for CUDA device linking, which will not generate an executable.

So how should I do it properly in windows?

Study some windows CUDA sample projects.

Compile those projects. Look at the compile command lines generated for the visual studio project, in the visual studio console window when the project is compiling. Use that to inform yourself about appropriate switch settings on windows, for nvcc, for your particular machine/install of CUDA.