Solved trying to build standalone app
-
@mzimmers said in trying to build standalone app:
What would cause make to look for the .dll version of the library when I'm specifying the .lib version?
Nothing. This is a loader error, not a linker error. You need to deploy the dependent libraries along with the application binary. On windows this most often means package the
dll
s alongside yourexe
's in the same folder. -
@kshegunov so there truly is no way to build an app that resides entirely within a single .exe file?
-
@mzimmers said in trying to build standalone app:
so there truly is no way to build an app that resides entirely within a single .exe file?
There is, however you must provide all the dependent libraries as static. On windows there's something called "import library" (or "stub library" as you got to know it above). This is only for linking purposes. What it does is basically state what kind of symbols are contained in the
dll
file and the MSVC linker reads it performs the symbol resolution (i.e. the linking) using it, not thedll
itself. You can even link againstdll
s without having the actualdll
s present, only by using the import lib. It's unfortunate, but windows also uses the same extensionlib
for static libraries. So to link against adll
you have the stub and the shared library, while for static libraries only thelib
file. I believe that's where your confusion stems from.Now back to how linking's done. If you have linked with an import library the linker will put a statement in the dll header that a specific dll is to be loaded. This happens when you start the program. There's a "utility" called the loader, which's responsible for loading the required modules and then transferring control to your
main()
. When you link statically there's no such first step of loading modules done, as the static binary is directly "injected" into your application. If, however, your static library depends on a dynamic one, this also propagates to your application; meaning that even if you built Qt statically, but you haven't used static libraries as its dependencies your application will include Qt's binary code, but it's going to still depend dynamically on Qt's dependencies.To have a "completely" stand-alone application you need to provide the whole tree of dependencies as static libraries. Then the linker can merge all the static code into one executable and it won't require
dll
s at load-time. This, beware, implies that you also need to provide even the C-runtime as a static library (in case of MSVC - the visual C runtime - msvcrt), which can be a real pain ... -
Hi @mzimmers ,
Just to add one important piece for dynamic linking on Windows, which was not explicited state before, I think:
- The
*.lib
file is needed at link time, it does not need to be deployed with the application - The
*.dll
file is needed at run time, it needs to be deployed
- The
-
@aha_1980 said in trying to build standalone app:
Hi @mzimmers ,
Just to add one important piece for dynamic linking on Windows, which was not explicited state before, I think:
- The
.lib
file is needed at link time, it does not need to be deployed with the application - The
*.dll
file is neede at run time, it needs to be deployed
@koahnig said in trying to build standalone app:
@mzimmers
For windows, either you have one lib or you have a lib and a dll. If you got both you need the lib for liniking and the dll for execution.I acknowledge, a bit hidden ;)
- The
-
Still fooling around with this...I borrowed the code below from somewhere:
myown_installs.files = "C:/Program Files (x86)/Expat 2.2.5/Bin/libexpat.lib" \ "C:/Program Files (x86)/Expat 2.2.5/Bin/libexpat.dll" myown_installs.path = $$OUT_PWD/release
Which works fine for my builds to the /release subdirectory, but not for debugs. Is there some clever way to conditionalize this in my project file?
-
Hi,
Are you trying to make a standalone debug application ?
-
Hi - no, but when I try to run the debugger, it crashes because these files aren't in the build directory.
-
Ok, I see. Then use
CONFIG(debug, debug|release){ # Debug specific stuff } else { # Release specific stuff }
-
I get a very unexpected error from this:
Any idea what I'm doing wrong?
-
You have a
}
just afterrelease
. -
Oh, brother...I'd downvote myself for that if I could.
It works fine now...thanks, SGaist.
-
No worries, things like that happen ;)