Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt Creator Project+CUDA build fails ... but ONLY in a Widget application! Please help!



  • Hello everyone! I'm new to Qt but learning quickly, and really excited about the kind of capabilities it can bring to my application. Without further ado, I'd really appreciate any help resolving this issue.

    I've got a QT Core application put together and have added CUDA capability combining tips and tricks from two locations:
    https://cudaspace.wordpress.com/2012/07/05/qt-creator-cuda-linux-review/
    and
    https://github.com/xixingyouyao/HelloCuda/blob/master/HelloCuda/HelloCuda.pro

    Everything is fine (compiling on Windows x64, with QT v5.10 x64 and Visual Studio 2015 x64 ... in my Core application (running in a console only). The problem is, when I use all the same code but make a couple changes to convert it to a Widgets application (with a QMainWindow), about a dozen strange build errors pop up, all of which seem to somehow relate to Windows headers? ... They make little sense because the errors all appear in files I never specifically included (they were probably #include'd by one of my header files)- but stuff like "xmemory.h" and "sal.h":

    `08:46:23: Starting: "C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\BIN\amd64\nmake.exe"

    "C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\BIN\amd64\nmake.exe" -f Makefile.Release
    C:\Qt\5.10.1\msvc2015_64\bin\uic.exe MyGUI.ui -o ui_MyGUI.h
    C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/bin/nvcc.exe --use_fast_math -I"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v9.1/include" -I"/common/inc/" -I"/../shared/inc/" -lcuda -lcudart --machine 64 -arch=sm_52 -c -o release\cuda\vectorAddition_cuda.o vectorAddition.cu
    cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -O2 -MD -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -D_UNICODE -DWIN32 -DWIN64 -DQT_DEPRECATED_WARNINGS -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I. -I"..\..\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.1\include" -I/common/inc/ -I/../shared/inc/ -I. -I..\..\Qt\5.10.1\msvc2015_64\include -I..\..\Qt\5.10.1\msvc2015_64\include\QtWidgets -I..\..\Qt\5.10.1\msvc2015_64\include\QtGui -I..\..\Qt\5.10.1\msvc2015_64\include\QtANGLE -I..\..\Qt\5.10.1\msvc2015_64\include\QtCore -Irelease -I. -I\include -I..\..\Qt\5.10.1\msvc2015_64\mkspecs\win32-msvc -Forelease\obj\
    

    @C:\Users\Max\AppData\Local\Temp\nm3F2A.tmp

    main.cpp
    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\xmemory(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\xmemory(15): error C2146: syntax error: missing ';' before identifier 'QT_END_NAMESPACE'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\xmemory(15): error C2143: syntax error: missing ';' before '{'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\xmemory(15): error C2447: '{': missing function header (old-style formal list?)

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\algorithm(1870): error C2061: syntax error: identifier '_Temp_iterator'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\algorithm(1901): error C2061: syntax error: identifier '_Temp_iterator'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\algorithm(2542): error C2061: syntax error: identifier '_Temp_iterator'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\algorithm(2829): error C2061: syntax error: identifier '_Temp_iterator'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\algorithm(2856): error C2061: syntax error: identifier '_Temp_iterator'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\memory(360): error C2061: syntax error: identifier 'auto_ptr'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\memory(433): note: see reference to class template instantiation 'std::_Ptr_base<_Ty>' being compiled

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\memory(514): error C2061: syntax error: identifier 'auto_ptr'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\memory(698): note: see reference to class template instantiation 'std::shared_ptr<_Ty>' being compiled

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\memory(585): error C2061: syntax error: identifier 'auto_ptr'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\memory(589): error C2805: binary 'operator =' has too few parameters

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\memory(1357): error C2061: syntax error: identifier 'auto_ptr'

    C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\INCLUDE\memory(1437): note: see reference to class template instantiation 'std::unique_ptr<_Ty,_Dx>' being compiled

    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\BIN\amd64\cl.EXE"' : return code '0x2'
    Stop.

    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\BIN\amd64\nmake.exe"' : return code '0x2'
    Stop.

    08:46:24: The process "C:\Program Files (x86)\Microsoft Visual Studio 2015\VC\BIN\amd64\nmake.exe" exited with code 2.

    Error while building/deploying project MyProject (kit: Desktop Qt 5.10.1 MSVC2015 64bit)

    The kit Desktop Qt 5.10.1 MSVC2015 64bit has configuration issues which might be the root cause for this problem.
    When executing step "Make"
    08:46:24: Elapsed time: 00:01.`

    Other errors talk about "QT_END_NAMESPACE" and "QT_START_NAMESPACE"- stuff I never put in my code to begin with!

    Switch back to a regular Core application with no UI, and these all go away. Similarly, the program is just fine with Widgets and a QMainWindow, but WITHOUT the changes to the .pro file for CUDA (no errors.) Are these somehow incompatible?

    For reference here is the working .pro file:
    https://pastebin.com/hDPmi5Mt

    ... and here is one with CUDA that yields the errors.
    https://pastebin.com/NMT9Bmcp

    To put a finer point on it: remove
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    and QT += gui and the problems go away. But then I can't have a GUI. :(

    I can provide more of the project code as needed to help diagnose the problem. Googled around for days now trying to find solutions and the best I've found is to include stuff like <windows.h> or <windefs.h> or <vector.h> or put the includes in different orders or move "using namespace std" to a different location, and NONE of these things have worked.

    Thanks so much for any assistance that anyone can provide. Hoping I don't have to switch away from Qt because of this. Or maybe I need to change to G++ compiler, but getting that to work with 64-bit target in Qt Creator sounds like a nightmare & I'd have to recompile my libs .... really hoping it's something simple, but I just cannot figure it out. :(

    Thanks again and have a nice day.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Not a direct answer but you might want to try to keep your CUDA related code in its own library and use that one with your GUI application.

    Depending on how you are using, keep the CUDA specific stuff in the implementation file and expose only interfaces that do not use CUDA includes.

    I don't say its not possible to have both together but it's been a very long time since I did that and IIRC, everything CUDA was its own library.



  • I see- that sounds like a good idea! Googling turned up a couple of gems of articles, but both apply to Ubuntu and Xcode(Mac OS X?) so I'll have to make it work with Windows 64-bit. Hopefully not too tough ... one thread says it's "easy", heh. I do plan to make the program run in Linux, too, so ...

    Any tips on how to do this in a single QT Creator project? Just hoping I won't need to juggle two projects and compile/build each when either changes (recipe for confusion).

    Will look further into this... thanks for the response :)


  • Lifetime Qt Champion

    @StarchyFortification

    Hi
    Just as a note
    Even you use QT += gui
    ( and the GUI parts are linked in)
    You dont need to have a windows or anything visible.
    But i assume you mean, you want a console app.



  • @mrjj Hi! Thanks for the reply. I'm trying to build a GUI application, but for some reason these build errors occurred whenever I had the arrangements for the GUI in the .pro file, including <QApplication> so forth. With <QCoreApplication> and just 'core' (no 'gui') it worked. So oddly: core+cuda=fine, gui+cuda=FAIL

    Trying the above suggestion of building an external library with the CUDA code in it and linking that into the GUI project in Qt Creator. I will report my findings. Testing as a DLL first... will probably also do static lib

    I am building the DLL in Visual Studio 2015 because CUDA toolkit provides some integration for doing this, but I think I can also just use nvcc.exe from the commandline to build my .dll/.lib (or static .lib). Figuring out external functions / export commands for DLL making ... etc


  • Lifetime Qt Champion

    You can use the subdir template and have all the projects needed under only one main project.


Log in to reply