Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Plugin and windows library(WS2_32.lib & User32.lib) linking fails
Forum Updated to NodeBB v4.3 + New Features

Qt Plugin and windows library(WS2_32.lib & User32.lib) linking fails

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 2.5k Views 3 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #1

    Hi

    I have trouble in linking WS2_32.lib and User32.lib with Qt plugin.

    Problem -
    App-
    I used ShellExecute(..) windows API in Qt App. Linked against WS2_32.lib and User32.lib. It worked fine. Application is also working.

    Now
    Plugins
    I used ShellExecute(..) windows API in Qt Plugin. Linked against WS2_32.lib and User32.lib. It is not linking. It always says linker error for ShellExecute(...).

    I'm using the MSVC 2017 64 bit.
    Please note that I have issue only if try to build Qt plugin(debug or release) & use windows API. Where as Qt Application works like a charm.

    Anything extra need to do while linking against windows library in plugins ?

    Dheerendra
    @Community Service
    Certified Qt Specialist
    http://www.pthinks.com

    raven-worxR 1 Reply Last reply
    0
    • dheerendraD dheerendra

      Hi

      I have trouble in linking WS2_32.lib and User32.lib with Qt plugin.

      Problem -
      App-
      I used ShellExecute(..) windows API in Qt App. Linked against WS2_32.lib and User32.lib. It worked fine. Application is also working.

      Now
      Plugins
      I used ShellExecute(..) windows API in Qt Plugin. Linked against WS2_32.lib and User32.lib. It is not linking. It always says linker error for ShellExecute(...).

      I'm using the MSVC 2017 64 bit.
      Please note that I have issue only if try to build Qt plugin(debug or release) & use windows API. Where as Qt Application works like a charm.

      Anything extra need to do while linking against windows library in plugins ?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @dheerendra said in Qt Plugin and windows library(WS2_32.lib & User32.lib) linking fails:

      Anything extra need to do while linking against windows library in plugins ?

      actually no.
      Regarding linking there is no difference for an executable or library.

      Did you build the executable (which you said is working) and the plugin (which doesn't work) on the same machine and the same compiler?!

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

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

        Hi
        One question. The plugins, are they Creator plugins?
        Or just plugins for your app ?
        Just checking as Creator plugins must be 32 bit.

        1 Reply Last reply
        1
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by dheerendra
          #4

          I have created my application plugin using the MSVC2017 64 bit. I have one class called DataCollector. Inside this I'm using the ShellExecute win32 call.

          If I use the datacollectod class directly(no plugin) inside my application, linking works. Application works.

          Same class(DataCollector) trying to convert as Qt Plugin. Pro file configurations are same. However when I compile it fails. It always says unresolved external symbol __imp_ShellExecuteW referenced in a function.

          @raven-worx I'm using same compiler, same system, same qt creator, same qt version. I'm not even closing Qt Creator. I have just written two pro file. One for plugin. One for App. Both use same source files and pro configuration. Plugin fails. App works.

          Looks very strange to me.

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            Issue is resolved. I added one more library for linking incase of Qt App Plugin.

            Qt Plugin -
            Failed : -luser32
            Pass : -luser32 -lshell32

            Qt App -
            PASS : -luser32
            Pass : -luser32 -lshell32

            It is very strange to me. I have no explanation on why it fails only in case of Qt Plugin.
            As of now it worked.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

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

              Hi,

              I haven't checked yet but it might be simply because that library is already a dependency used by one of the Qt module you are using for your application.

              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
              • dheerendraD Offline
                dheerendraD Offline
                dheerendra
                Qt Champions 2022
                wrote on last edited by dheerendra
                #7

                @SGaist practically it should be like that only. Otherwise it would not have compiled for app as well. Hence I made all qmake configuration same for both app & plugin. Only change is TEMPLATE=lib and TEMPLATE=app. Still it was same issue. Thats where it surprised me as well.

                Finally I looked at qtbase/src/plugins/platforms/windows/windows.pri file as it is also a plugin & uses lot many win32 calls. It linked 4 additional libraries. I just did trial & error with each of linked libraries. My issue resolved for -lshell32.

                Dheerendra
                @Community Service
                Certified Qt Specialist
                http://www.pthinks.com

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

                  To avoid trial and error, you can lookup the API you use on MSDN, their documentation states which library you have too link to when using one of their APIs.

                  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
                  0

                  • Login

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