Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Qt 6 and CUDA fail to compile

Qt 6 and CUDA fail to compile

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
4 Posts 4 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cwade
    wrote on last edited by
    #1

    I am trying to use CUDA in conjunction with Qt 6 and am unable to get it to compile. I am using a completely empty project, except for a main.cpp and a cuda class (.h/.cu). When I try to import any Qt class into the .cu class, the program fails to compile. Here is the project setup:

    CMakeLists.txt:

    cmake_minimum_required(VERSION 3.14)
    
    project(Qt6CUDA LANGUAGES CXX CUDA)
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)
    
    add_executable(Qt6CUDA
      main.cpp
      cuda_class.h
      cuda_class.cu
    )
    
    set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 87)
    
    # Qt 6 requires C++ 17
    target_compile_options(${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:
        --std=c++17;
        -Zc:__cplusplus>)
    
    target_link_libraries(Qt6CUDA Qt${QT_VERSION_MAJOR}::Core)
    

    main.cpp:

    #include <QCoreApplication>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        return a.exec();
    }
    

    cuda_class.h:

    #ifndef CUDACLASS_H
    #define CUDACLASS_H
    
    class CudaClass
    {
        public:
            CudaClass();
    };
    
    #endif // CUDACLASS_H
    

    cuda_class.cu:

    #include "cuda_class.h"
    
    #include <QVector> // This line prevents the program from compiling
    
    CudaClass::CudaClass()
    {
    
    }
    

    Starting with the CMake, I simply enable language support for CUDA add compile options for C++ 17 (since Qt 6 requires C++ 17). I added a simple CUDA class that only includes QVector as an example. It does not seem to matter what Qt class I include, it fails in the same way for all I have tried.

    When I try to compile I get the following output:

    13:23:01: Running steps for project Qt6CUDA...
    13:23:01: Starting: "C:\Program Files\CMake\bin\cmake.exe" --build C:/Users/i3w/Documents/build-Qt6CUDA-Desktop_Qt_6_3_0_MSVC2019_64bit-Debug --target all
    [0/1 ?/sec] Re-running CMake...
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/Users/i3w/Documents/build-Qt6CUDA-Desktop_Qt_6_3_0_MSVC2019_64bit-Debug
    [1/4 19.4/sec] Automatic MOC and UIC for target Qt6CUDA
    [2/3 1.0/sec] Building CUDA object CMakeFiles\Qt6CUDA.dir\cuda_class.cu.obj
    FAILED: CMakeFiles/Qt6CUDA.dir/cuda_class.cu.obj 
    C:\PROGRA~1\NVIDIA~2\CUDA\v11.7\bin\nvcc.exe -forward-unknown-to-host-compiler -DQT_CORE_LIB -DUNICODE -DWIN32 -DWIN64 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -D_UNICODE -D_WIN64 -IC:\Users\i3w\Documents\build-Qt6CUDA-Desktop_Qt_6_3_0_MSVC2019_64bit-Debug -IC:\Users\i3w\Documents\Qt6CUDA -IC:\Users\i3w\Documents\build-Qt6CUDA-Desktop_Qt_6_3_0_MSVC2019_64bit-Debug\Qt6CUDA_autogen\include -isystem=C:\Qt\6.3.0\msvc2019_64\include\QtCore -isystem=C:\Qt\6.3.0\msvc2019_64\include -isystem=C:\Qt\6.3.0\msvc2019_64\mkspecs\win32-msvc -D_WINDOWS -Xcompiler="/W3 /GR /EHsc" -Xcompiler="-MDd -Zi -Ob0 -Od /RTC1" --generate-code=arch=compute_87,code=[compute_87,sm_87] --std=c++17 -Zc:__cplusplus -std=c++17 -MD -MT CMakeFiles\Qt6CUDA.dir\cuda_class.cu.obj -MF CMakeFiles\Qt6CUDA.dir\cuda_class.cu.obj.d -x cu -c C:\Users\i3w\Documents\Qt6CUDA\cuda_class.cu -o CMakeFiles\Qt6CUDA.dir\cuda_class.cu.obj -Xcompiler=-FdCMakeFiles\Qt6CUDA.dir\,-FS
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qlogging.h(156): warning #1394-D: field of class type without a DLL interface used in a class with a DLL interface
    
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qtypeinfo.h(114): error: expected an expression
              detected during instantiation of class "QTypeInfoMerger<T, Ts...> [with T=std::pair<T1, T2>, Ts=<T1, T2>]" 
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qpair.h(62): here
    
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qtypeinfo.h(114): error: fold expression does not refer to a parameter pack
              detected during instantiation of class "QTypeInfoMerger<T, Ts...> [with T=std::pair<T1, T2>, Ts=<T1, T2>]" 
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qpair.h(62): here
    
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qtypeinfo.h(115): error: expected an expression
              detected during instantiation of class "QTypeInfoMerger<T, Ts...> [with T=std::pair<T1, T2>, Ts=<T1, T2>]" 
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qpair.h(62): here
    
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qtypeinfo.h(115): error: fold expression does not refer to a parameter pack
              detected during instantiation of class "QTypeInfoMerger<T, Ts...> [with T=std::pair<T1, T2>, Ts=<T1, T2>]" 
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qpair.h(62): here
    
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qbytearray.h(91): warning #1394-D: field of class type without a DLL interface used in a class with a DLL interface
    
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qstring.h(1099): warning #1394-D: field of class type without a DLL interface used in a class with a DLL interface
    
    C:\Qt\6.3.0\msvc2019_64\include\QtCore/qstringmatcher.h(85): warning #1394-D: field of class type without a DLL interface used in a class with a DLL interface
    
    4 errors detected in the compilation of "C:/Users/i3w/Documents/Qt6CUDA/cuda_class.cu".
    cuda_class.cu
    ninja: build stopped: subcommand failed.
    13:23:03: The process "C:\Program Files\CMake\bin\cmake.exe" exited with code 1.
    Error while building/deploying project Qt6CUDA (kit: Desktop Qt 6.3.0 MSVC2019 64bit)
    When executing step "Build"
    13:23:03: Elapsed time: 00:02.
    

    This same setup used to work with Qt 5 and older C++ language standards. The issue seems to be related to fold expressions used in qtypeinfo.h. If the #include <QVector> is not included in the .cu file, everything compiles file. Note, I am not trying to use any Qt in CUDA device code, simply import and use Qt classes within host only functions.

    I am building with MSVC 2019 64-bit, Qt 6.3.0, and NVCC version 11.7 . This is the kit configuration:
    kit_config.JPG

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sthlm58
      wrote on last edited by
      #2

      @cwade Did you manage to solve this issue (in a way that doesn't require to remove Qt from *.cu files)?

      I 1 Reply Last reply
      0
      • S sthlm58

        @cwade Did you manage to solve this issue (in a way that doesn't require to remove Qt from *.cu files)?

        I Offline
        I Offline
        Irodov
        wrote on last edited by
        #3

        @sthlm58 I have the same problem, did any of you find a solution?

        1 Reply Last reply
        0
        • X Offline
          X Offline
          Xinlong
          wrote on last edited by
          #4

          I am having exactly the same problem.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved