Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Can i use Libtorch library on QT Creator with qmake?
Forum Updated to NodeBB v4.3 + New Features

Can i use Libtorch library on QT Creator with qmake?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
16 Posts 5 Posters 4.3k Views 2 Watching
  • 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.
  • M Offline
    M Offline
    mesut.toruk
    wrote on last edited by
    #1

    I need to integrate my Torch project to QT GUI? But i can not use Torch Libraries on QT. I got some errors like below.(OS: Windows10)

    libtorch\include\torch\csrc\jit\ir.h:1077: error: function 'torch::jit::Value* torch::jit::Graph::insertGetAttr(torch::jit::Value*, const string&)' definition is marked dllimport
    TORCH_API Value* insertGetAttr(Value* obj, const std::string& field)```
    

    I added libtorch to .pro file:

    QMAKE_CXXFLAGS += -DGLIBCXX_USE_CXX11_ABI=0
    
    INCLUDEPATH += "$$PWD\libtorch\include"
    INCLUDEPATH += "$$PWD\libtorch\include\torch\csrc\api\include"
    
    LIBS += -L$$PWD/libtorch/lib
    LIBS += -ltorch -lc10
    

    I also create new issue in this post: [https://github.com/pytorch/pytorch/issues/22792] However, i could not solve my problem.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      Hi and welcome to devnet,

      Did you follow the link provided in your GitHub issue ?

      It seems that "CONFIG += no_keywords" added to your .pro file should do the trick.

      [edit: Fixed the .pro file line SGaist]

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi
        Its seems it's not available for Windows with mingw/visual studio. (c++)
        vs could work as @SGaist found. with workaround.
        https://github.com/pytorch/pytorch/issues/19405
        However, it being a python thing, could you not use it natively with Qt for Python ?
        https://www.qt.io/qt-for-python

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mesut.toruk
          wrote on last edited by
          #4

          new .pro file:
          QMAKE_CXXFLAGS += -DGLIBCXX_USE_CXX11_ABI=0
          CONFIG += no_keywords

          INCLUDEPATH += "$$PWD\libtorch\include"
          INCLUDEPATH += "$$PWD\libtorch\include\torch\csrc\api\include"

          LIBS += -L$$PWD/libtorch/lib
          LIBS += -ltorch -lc10

          and i added to code:

          #undef slots
          #include "torch/torch.h"
          #include "torch/script.h"
          #def slots Q_SLOTS

          It does not work. It gives same error.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What version of Qt are you using ?
            What compiler are you using ?
            Which version of the compiler ?

            Also, use forward slashes for paths. Qt handles the transformation to native path and it will avoid escaping issues.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            2
            • M Offline
              M Offline
              mesut.toruk
              wrote on last edited by
              #6

              QT Creator 4.8.2
              MinGW 7.3.0 64 bit

              I adjusted forward slashes for paths.

              jsulmJ 1 Reply Last reply
              0
              • M mesut.toruk

                QT Creator 4.8.2
                MinGW 7.3.0 64 bit

                I adjusted forward slashes for paths.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #7

                @mesut.toruk said in Can i use Libtorch library on QT Creator with qmake?:

                QT Creator 4.8.2

                This is not Qt version...

                "I adjusted forward slashes for paths." - and rerun qmake and rebuild?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Might be silly question but do you currently have a MinGW build of lib torch ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • M Offline
                    M Offline
                    mesut.toruk
                    wrote on last edited by
                    #9

                    QT 5.12.2.
                    No, i do not have MinGW build of lib torch. Then this post, i looked for it. It seems hard. They recommend using MSVC. I installed Visual Studio 2017 and tried to set compiler. I guess, I couldn't do it right. How can i add MSVC 2017 to Tools>Options>Kits>Compilers?

                    My error:

                    13:21:15: Could not determine which "make" command to run. Check the "make" step in the build configuration.
                    Error while building/deploying project t2 (kit: Desktop Qt 5.12.2 MSVC2017 64bit)
                    When executing step "qmake"
                    
                    aha_1980A 1 Reply Last reply
                    0
                    • M mesut.toruk

                      QT 5.12.2.
                      No, i do not have MinGW build of lib torch. Then this post, i looked for it. It seems hard. They recommend using MSVC. I installed Visual Studio 2017 and tried to set compiler. I guess, I couldn't do it right. How can i add MSVC 2017 to Tools>Options>Kits>Compilers?

                      My error:

                      13:21:15: Could not determine which "make" command to run. Check the "make" step in the build configuration.
                      Error while building/deploying project t2 (kit: Desktop Qt 5.12.2 MSVC2017 64bit)
                      When executing step "qmake"
                      
                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @mesut.toruk said in Can i use Libtorch library on QT Creator with qmake?:

                      How can i add MSVC 2017 to Tools>Options>Kits>Compilers?

                      You cannot. Creator auto-detects it. Where did you install Visual Studio 2017? Did you install the C++ compiler too?

                      Regards

                      Qt has to stay free or it will die.

                      M 1 Reply Last reply
                      1
                      • aha_1980A aha_1980

                        @mesut.toruk said in Can i use Libtorch library on QT Creator with qmake?:

                        How can i add MSVC 2017 to Tools>Options>Kits>Compilers?

                        You cannot. Creator auto-detects it. Where did you install Visual Studio 2017? Did you install the C++ compiler too?

                        Regards

                        M Offline
                        M Offline
                        mesut.toruk
                        wrote on last edited by
                        #11

                        @aha_1980
                        I installed C:/Program Files/Microsoft Visual Studio. I also installed C++ compiler. It is "cl.exe" in Visual Studio.

                        aha_1980A 1 Reply Last reply
                        0
                        • M mesut.toruk

                          @aha_1980
                          I installed C:/Program Files/Microsoft Visual Studio. I also installed C++ compiler. It is "cl.exe" in Visual Studio.

                          aha_1980A Offline
                          aha_1980A Offline
                          aha_1980
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          Hi @mesut.toruk,

                          I installed C:/Program Files/Microsoft Visual Studio. I also installed C++ compiler. It is "cl.exe" in Visual Studio.

                          And the compiler is not auto-detected in Tools > Options > Kits > Compilers ?

                          Qt has to stay free or it will die.

                          M 1 Reply Last reply
                          1
                          • aha_1980A aha_1980

                            Hi @mesut.toruk,

                            I installed C:/Program Files/Microsoft Visual Studio. I also installed C++ compiler. It is "cl.exe" in Visual Studio.

                            And the compiler is not auto-detected in Tools > Options > Kits > Compilers ?

                            M Offline
                            M Offline
                            mesut.toruk
                            wrote on last edited by mesut.toruk
                            #13

                            @aha_1980
                            No it is not. Should Qt install MSVC? While i install QT, i marked MSVC. But there is no MSVC in C:\Qt\Tools. However, there is qmake in C:\Qt\5.12.2\msvc2017\bin. I installed externally Visual Studio and tried to add it. It gives error.

                            jsulmJ 1 Reply Last reply
                            0
                            • M mesut.toruk

                              @aha_1980
                              No it is not. Should Qt install MSVC? While i install QT, i marked MSVC. But there is no MSVC in C:\Qt\Tools. However, there is qmake in C:\Qt\5.12.2\msvc2017\bin. I installed externally Visual Studio and tried to add it. It gives error.

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @mesut.toruk said in Can i use Libtorch library on QT Creator with qmake?:

                              Should Qt install MSVC

                              No, QtCreator should auto detect Microsoft C++ compiler. Can you show your compiler tab?
                              Which Visual Studio version did you install?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              M 1 Reply Last reply
                              0
                              • jsulmJ jsulm

                                @mesut.toruk said in Can i use Libtorch library on QT Creator with qmake?:

                                Should Qt install MSVC

                                No, QtCreator should auto detect Microsoft C++ compiler. Can you show your compiler tab?
                                Which Visual Studio version did you install?

                                M Offline
                                M Offline
                                mesut.toruk
                                wrote on last edited by mesut.toruk
                                #15

                                @jsulm
                                I installed Visual Studio 2017 and Visual Studio 2019.

                                0_1563786116733_Ekran Alıntısı.PNG

                                jsulmJ 1 Reply Last reply
                                0
                                • M mesut.toruk

                                  @jsulm
                                  I installed Visual Studio 2017 and Visual Studio 2019.

                                  0_1563786116733_Ekran Alıntısı.PNG

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @mesut.toruk The Microsoft compilers were not auto detected.
                                  Did you install the C++ parts of Visual Studio (those are not automatically installed)?
                                  If so, then try to deinstall QtCreator and install it again.

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  1

                                  • Login

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