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

Crash when run in Release mode?



  • Hi,
    My program run in debug mode without any crash but when I run it release mode then rash message appear.
    I clean and delete all build directory but nothing changes?! :(
    Any advice?

    14:15:46: Starting D:\Belgeler\Qt\build-mriERP-Desktop_Qt_5_14_2_MSVC2017_64bit-Release\release\mriERP.exe ...
    14:15:46: The program has unexpectedly finished.
    14:15:46: The process was ended forcefully.
    14:15:46: D:\Belgeler\Qt\build-mriERP-Desktop_Qt_5_14_2_MSVC2017_64bit-Release\release\mriERP.exe crashed.
    

    Regards,
    Mucip:)



  • The first thing I'd check is, did the files copy over to the release directory?

    I was making an assumption that you had those files available in your source directory; if not, then you need to furnish the pathnames in the .pro file.



  • @Mucip
    You will (probably) have a bug in code which happens to show up in Release but not in Debug. This has been discussed before in this forum, e.g. uninitialised variable. It happens. Can be hard to trace down.

    Try running your Release executable under debugger. When it crashes inside debugger you still get trace back. If you are lucky, and it can see your source code, you may get enough to see where it is happening....



  • Hi @JonB,
    The code was running Qt 5.13 without any problem. But I use on new computer Qt 5..14.2 now and I got this crash unfotunatelly.
    May it be because of VS 2019 new update?...

    How can I run release executable under debuger?

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    @Mucip said in Crash when run in Release mode?:

    How can I run release executable under debuger?

    In the same way you run a debug build



  • @jsulm ,
    If I press debug button in release uild than I got below error?

    cd6fef54-8206-4234-9cbd-ef5d9eb8ef83-resim.png

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    @Mucip So, does your app even start in release mode? Or is it crashing before even showing?
    If the latter then probably some libs are not found for release build.


  • Moderators

    @Mucip said in Crash when run in Release mode?:

    VS 2019

    MSVC is not fully supported with Qt ( 2017 is) I've run into 1 or 2 error because of that as well. Did you update/use the latest MSVC when you installed VS2019 or did you check that?



  • @Mucip
    Forget the boxes for a second. You show the release one crashed. Did it not stop in debugger at that point and allow you to see traceback?



  • @J-Hilk ,
    I did not do extra things when I install VS2019. How will I update MSVC2019?

    Regards,
    Mucip:)



  • @JonB ,
    In debugger mode the debug button works well as below screenshot

    b3c53fdd-c88a-4e5a-ae97-d0fe07852fc6-resim.png

    Regards,
    Mucip:)



  • @J-Hilk
    Something wrong in VS2019 I guess too :(

    No solution untill now. Should I install VS2017???

    Regards,
    Mucip:)



  • @J-Hilk ,
    How can I check it please?

    Regards,
    Mukcip:)



  • @J-Hilk ,
    It's very strange!

    When I build in RELEASE mode I got crash and can not run under Qt Creator!
    But when I run windployqt and create executable of the project than it works without any problem!
    I can connect to PostgreSQL and use LimeReport and QtZint. I mean all the DLL's work without any problem.

    Project can be compiled in the release directory but can not be run via Qt... :(

    Well, Where should be the problem?! I guess Qt must update something according to actual version of VS2019... :(

    Regards,
    Mucip:)



  • I encounter this every so often. The cause is usually what JSulm suggested -- a missing library. If your project file isn't too big, I'd be interested in looking at it.

    One thing I do when I encounter this, is go to the release directory and try to run the .exe directly (outside of Creator). You'll likely get an error message telling you what's wrong (eg, which library is missing).



  • Hi @mzimmers ,
    If some DLL is misssing, It shouldn't be compiled. But QtCretator can compile the project.
    Am I rigt?
    By the way it shouldn't run in DEBUG mode either.

    P.S. Thanks a lot for your kind interest. Project is liitle bit long. :)

    Regards,
    Mucip:)



  • @Mucip it's not that the .dll is missing - it's just not accessible to the release image. (I'm probably not the best one to explain this.) This would be a useful experiment: go into your build directory for your debug build. Find the executable and try to run it (this should work). Then go into the build directory for your release build, and do the same thing. I'm expecting you'll get an error message from the binary; if so, please post it.



  • Dear @mzimmers ,
    Well, I tested in DEBUG directory. Clicked MriERP.exe file. Ofcourse it says LimeReport, QtZint and QtCore and etc files are missing. When I copy these files in the debug directory I can run the program in DEBUG folder.

    When I try same thing in RELEASE folder, error messages are the same. Same files are missing. I copied LimeReport, QtZint and Qt's DLL files than MriERP.exe files worked normally too.

    A quick question: If some DLL are missing It shouldn't compile the project, should it?...

    Regards,
    Mucip:)



  • Thanks for running those tests. I misspoke when I said the debug version should run; I forgot that the libraries aren't available outside of Creator. Since you probably don't intend to run your debug version outside of Qt, that's not important.

    To fix your release build, you need to do (at least) two things:

    1. tell Creator which files (the ones you mentioned)you want to copy to your build directory. This can be done like this (in your .pro file):
    my_release.files = "libexpat.lib"
    my_release.path = $$OUT_PWD
    
    INSTALLS += my_release
    
    1. in your build settings, you need to add a step after make, to do a make install. This will copy the files for you.
      build.PNG

    This should not work, but might not be exactly what you want. The user can run your program out of the release directory, but if he moves the executable, it won't run. If this presents a problem, let me know, and I'll tell you how to fix this (but it will take you some time to do so).



  • @mzimmers said in Crash when run in Release mode?:

    my_release.files = "libexpat.lib"
    my_release.path = $$OUT_PWD

    INSTALLS += my_release

    Hi,
    How can I put two dll files in the my_release.files? Should I add path also?

    By the way, what is changed after Qt 5.13.2? I didn't make this modification before? Why it happend in Qt 5.14.2?

    By the way if I copy LimeReport.dll and QtZint.dll to RELEASE folder, I can run the program in Qt Creator. This mean the problem was LimeReport.dll and QtZint.dll files missing!

    But why? It was working in Qt5.13.2 before???

    Regards,
    Mucip:)



  • @Mucip

    target.path = $$OUT_PWD
    target.files = "LimeReport.dll" "QtZint.dll"
    INSTALLS += target
    

    This link OUT_PWD will explain how it works.

    Just make sure to add the install step to your build. Adding this stuff to the .pro files is just specifying what the install will work on.

    I can't answer why it worked in 5.13.



  • @mzimmers said in Crash when run in Release mode?:

    target.path = $$OUT_PWD
    target.files = "LimeReport.dll" "QtZint.dll"
    INSTALLS += target

    Hi @mzimmers,
    I copied above lines in my pro file and add make step to build like below picture. But still same crash?!
    I affraid I could not copy dll's to destination folder. :(
    Where am I wrong?...

    b37518d7-c68b-4028-b6da-38022be3400f-resim.png

    Regards,
    Mucip:)



  • The first thing I'd check is, did the files copy over to the release directory?

    I was making an assumption that you had those files available in your source directory; if not, then you need to furnish the pathnames in the .pro file.



  • @mzimmers ,
    No. Files did not copied in the folder. But when I add below string than everything solved. I can run program in release mode too.

    target.path = $$OUT_PWD
    target.files = "D:/Belgeler/Qt/LimeReport/win64/release/lib/LimeReport.dll" "D:/Belgeler/Qt/LimeReport/win64/release/lib/QtZint.dll"
    INSTALLS += target
    

    Thanks...

    Regards,
    Mucip:)



  • Excellent. If you like, you can create a variable in your .pro file for your directory that contains the libraries, and use that variable when specifying the target.files. Won't change the behavior; it's just a bit cleaner.

    If you think this is resolved, please mark the topic as solves using the topic tools available in your first post in this thread.



  • @mzimmers
    I already marked your post as answer... :)

    By the way there is still one question more: What is the difference between 5.13.2 and 5.14.2?... :)

    Regards,
    Mucip:)


  • Lifetime Qt Champion

    @Mucip That is something that you can find out in the release notes as well as in the git history.



  • @SGaist said in Crash when run in Release mode?:

    @Mucip That is something that you can find out in the release notes as well as in the git history.

    But whatever the differences are, I seriously doubt they have anything to do with the problem you encountered. More likely, when you updated, you also created a new .user file that wiped out your build settings.



  • Hi @mzimmers ,
    In any case, I learned new and very usefull things. Thanks.

    Regards,
    Mucip:)



  • Hi @mzimmers ,
    Let's suppose there is report folder in the main project directory and some xml files in this report directory. I want to copy report folder and contents to the target directory too. Above information I can copy files to target but what about create folder and copy files to target directory on compile time?

    Regards,
    Mucip:)



  • @Mucip yes, you can do that. The details can be found here.



  • @mzimmers ,
    I got it thanks.
    Maybe someone has same problem. I solved like below.
    The code create "rapor" folder and copies contents to target build directory.

    target.path = $$OUT_PWD/release
    target.files = "D:/Belgeler/Qt/LimeReport/win64/release/lib/LimeReport.dll" "D:/Belgeler/Qt/LimeReport/win64/release/lib/QtZint.dll" $$PWD/rapor
    INSTALLS += target
    

    Regards,
    Mucip:)



  • Looks good. Thanks for posting the solution.


  • Lifetime Qt Champion

    @Mucip said in Crash when run in Release mode?:

    If some DLL are missing It shouldn't compile the project, should it?

    If they are missing at compile time then yes it will not compile.
    But in your case they are missing at runtime.
    QtCreator prepares the environment before starting your app, so it can find all libraries.
    If you want to start your app outside of Qt creator you need to deploy it first: https://doc.qt.io/qt-5/windows-deployment.html



  • @jsulm ,
    No. I already use and know WinDeployQt. The problem was here is, I can not run the RELEASE build inner Qt Creator. And when I add above lines to the pro file than I can run the RELEASE build inner Qt Creator too.

    Regards,
    Mucip:)


Log in to reply