Solved Qt Plugin and windows library(WS2_32.lib & User32.lib) linking fails
-
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 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?!
-
Hi
One question. The plugins, are they Creator plugins?
Or just plugins for your app ?
Just checking as Creator plugins must be 32 bit. -
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.
-
Issue is resolved. I added one more library for linking incase of Qt App Plugin.
Qt Plugin -
Failed : -luser32
Pass : -luser32 -lshell32Qt App -
PASS : -luser32
Pass : -luser32 -lshell32It is very strange to me. I have no explanation on why it fails only in case of Qt Plugin.
As of now it worked. -
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.
-
@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.
-
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.