Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

trying to build standalone app



  • Hi all -

    I'm trying to build a standalone Qt application. In my qmake.pro file, I have the following line:

    LIBS += "C:\Program Files (x86)\Expat 2.2.5\Bin\libexpat.lib"
    

    But when I try to run, I get this error:

    The code execution cannot proceed because libexpat.dll was not found. Reinstalling the program may fix this problem. 
    

    What would cause make to look for the .dll version of the library when I'm specifying the .lib version?

    Thanks...



  • @mzimmers said in trying to build standalone app:

    LIBS += "C:\Program Files (x86)\Expat 2.2.5\Bin\libexpat.lib"
    

    Typically you should use forward slashes '/' .AFAIK '\' is interpret as escape sequence.

    But when I try to run, I get this error:

    The code execution cannot proceed because libexpat.dll was not found. Reinstalling the program may fix this problem. 
    

    What would cause make to look for the .dll version of the library when I'm specifying the .lib version?

    You are probably linking to the so-called stub-library. Under windows you generate for each dll also the lib holding stubs indicating how the access to the dll routines has to be.

    [edit, koahnig] This might give a better explanation



  • @mzimmers hi,
    You need to put the dll in your app executable folder.
    If you want everything in your .exe file you have to do static build

    you can first build qt itself statically, and then build your app and the libexpat with that static version of qt



  • @koahnig so even though I'm copying over the lib file, I need to copy the dll, too? That's not really very standalone, is it?



  • @LeLev I'm trying to do a static build. I've built a static version of Qt, but my app build doesn't seem to be static. I must be missing a step.



  • @mzimmers

    AFAIK this is only for windows. I get confused on linux ;)

    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.



  • @mzimmers said in trying to build standalone app:

    @LeLev I'm trying to do a static build. I've built a static version of Qt, but my app build doesn't seem to be static. I must be missing a step.

    AFAIK you can mix. If there is one stub lib, you will need also the dll for that stub lib.



  • @mzimmers you need static version of your lib also



  • @koahnig yeah, that was it...I moved both the .lib and the .dll file, and it runs. Thanks for the information about those stub libraries; I'd never heard of that.


  • Qt Champions 2017

    @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 dlls alongside your exe's in the same folder.



  • @kshegunov so there truly is no way to build an app that resides entirely within a single .exe file?


  • Qt Champions 2017

    @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 the dll itself. You can even link against dlls without having the actual dlls present, only by using the import lib. It's unfortunate, but windows also uses the same extension lib for static libraries. So to link against a dll you have the stub and the shared library, while for static libraries only the lib 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 dlls 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 ...


  • Lifetime Qt Champion

    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


  • @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 ;)



  • 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?


  • Lifetime Qt Champion

    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.


  • Lifetime Qt Champion

    Ok, I see. Then use

    CONFIG(debug, debug|release){
        # Debug specific stuff
    } else {
        # Release specific stuff
    }
    


  • I get a very unexpected error from this:0_1548282879804_creator.PNG

    Any idea what I'm doing wrong?


  • Lifetime Qt Champion

    You have a } just after release.



  • Oh, brother...I'd downvote myself for that if I could.

    It works fine now...thanks, SGaist.


  • Lifetime Qt Champion

    No worries, things like that happen ;)


Log in to reply