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

Linux application crashes.



  • I create a console application on Linux.

    #include <QCoreApplication>
    
    #include "udp.h"
    #include "sys.h"
    
    static QString sys_params_file;
    
    int main(int argc, char *argv[])
    {  
        QCoreApplication a(argc, argv);
      
       sys_params_file = QCoreApplication::applicationDirPath() + "/sys_params.xml";
    
        rt_params.connected = UDP_Start(sys_params.local_ip, sys_params.local_port);
      
        if (rt_params.connected)
            printf ("UDP socket connected\n");
        else
            printf ("UDP socket failed to connect\n");
     
         return a.exec();
    }
    

    I set a break point on QCoreApplication a(argc, argv); - but before I get there it shows an exception several times and that's it.

    The inferior stopped because it received a signal from the operating system.
    Signal name : SIGSTOP
    Signal meaning : Stopped (signal)

    What can I check? It's hard to debug, it stops at the disassembly window - I can't get anything from assembly instructions.



  • @jenya7
    When it stops find the stack trace (not disassembly) pane of the debugger. That may contain a clue as to where it is coming from.

    Just one thought: you have a static QString, created before the QCoreApplication. Although this should be OK for a QString, if you have some other static Qt objects elsewhere they might cause a problem. Do you?



  • @JonB said in Linux application crashes.:

    @jenya7
    When it stops find the stack trace (not disassembly) pane of the debugger. That may contain a clue as to where it is coming from.

    Just one thought: you have a static QString, created before the QCoreApplication. Although this should be OK for a QString, if you have some other static Qt objects elsewhere they might cause a problem. Do you?

    Can not find the stack trace window.
    Of course I have static objects, plenty in every file. If I don't declare it as static - I get -
    warning: no previous extern declaration for non-static variable
    And it's perfectly right - it's data encapsulation.

    I see a Stack window but it's empty.


  • Lifetime Qt Champion

    @jenya7 said in Linux application crashes.:

    Of course I have static objects, plenty in every file

    Why? You should avoid static variables as much as possible.

    "warning: no previous extern declaration for non-static variable" - C++ is an object oriented language, you should not need too many stand alone variables, use class members instead. Please show one example where you get this eeror, so we can suggest a solution.

    "Can not find the stack trace window" - it's right there in debug view.

    Also, you are not allowed to instantiate any QObject based variables before you create QApplication instance! So, if you have any QObject based static variables it is not going to work...



  • @jsulm said in Linux application crashes.:

    @jenya7 said in Linux application crashes.:

    Of course I have static objects, plenty in every file

    Why? You should avoid static variables as much as possible.

    "warning: no previous extern declaration for non-static variable" - C++ is an object oriented language, you should not need too many stand alone variables, use class members instead. Please show one example where you get this eeror, so we can suggest a solution.

    "Can not find the stack trace window" - it's right there in debug view.

    I see. Indeed the variables are not members of a class. I have some files without classes. Could be the issue?

    I removed all static objects. For now it looks like this

    #include <QCoreApplication>
    
    //#include "udp.h"
    //#include "sys.h"
    
    //static QString sys_params_file;
    
    int main(int argc, char *argv[])
    {  
        QCoreApplication a(argc, argv);
     
         printf ("Hello\n");
      
         return a.exec();
    }
    

    Still the same problem. The exception arises at _start function, it's before my app comes in play as I understand.



  • @jenya7 said in Linux application crashes.:

    And it's perfectly right - it's data encapsulation

    No, having global/static objects is not a great idea. In any case, as I said a large number of Qt objects cannot/must not be defined as static/global, because they cannot be instantiated before QCoreApplication has been created, whether you think that is a good idea or not.

    Try this now for your test program:

    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {  
        printf ("Hello World\n");
        return 0;
    }
    

    If that gives the same behaviour --- as I am hoping it will, then you know you do not have a Qt issue.


  • Lifetime Qt Champion

    @jenya7 said in Linux application crashes.:

    The exception arises at _start function, it's before my app comes in play as I understand.

    Could indicate that some libs or Qt plug-ins are not found/loaded.
    Set QT_DEBUG_PLUGINS in Run settings of your app and see what output you get (you can also post it here).
    How did you install Qt?



  • @jsulm said in Linux application crashes.:

    @jenya7 said in Linux application crashes.:

    The exception arises at _start function, it's before my app comes in play as I understand.

    Could indicate that some libs or Qt plug-ins are not found/loaded.
    Set QT_DEBUG_PLUGINS in Run settings of your app and see what output you get (you can also post it here).
    How did you install Qt?

    I installed it like this

    sudo apt-get update
    sudo apt-get upgrade
    sudo apt-get install qt5-default
    sudo apt-get install qtcreator
    sudo apt-get install qtdeclarative5-dev
    sudo apt-get install qtbase5-examples
    sudo apt-get install qtbase5-doc-html
    

    I found a widget app, I created several months ago - it runs, no problem. It also has in a *.pro file
    QT += core
    QT += network
    QT += xml
    I thought one of these causes the problem.
    How do I set QT_DEBUG_PLUGINS?



  • @JonB said in Linux application crashes.:

    @jenya7 said in Linux application crashes.:

    And it's perfectly right - it's data encapsulation

    No, having global/static objects is not a great idea. In any case, as I said a large number of Qt objects cannot/must not be defined as static/global, because they cannot be instantiated before QCoreApplication has been created, whether you think that is a good idea or not.

    Try this now for your test program:

    #include <stdio.h>
    
    int main(int argc, char *argv[])
    {  
        printf ("Hello World\n");
        return 0;
    }
    

    If that gives the same behaviour --- as I am hoping it will, then you know you do not have a Qt issue.

    The same problem.


  • Lifetime Qt Champion

    @jenya7 said in Linux application crashes.:

    How do I set QT_DEBUG_PLUGINS?

    Right side in QtCreator->Projects->Run->Run Environment, then add there QT_DEBUG_PLUGINS with value 1.



  • @jenya7
    As I suspected :( You could now also remove the #include <stdio.h> and the printf() just to rule out any possible I/O issue.

    Assuming that too fails, you have a problem!

    What Linux are you on, are you fully patched, I assume your gcc came with the OS, does that need updating?

    Since this means you cannot run any C/C++ program, how long has this been happening to you? Is this the first time you have ever tried, or did it use to work but not now?

    Experiments with Qt and QT_DEBUG_PLUGINS are now pointless, since your fault occurs with nothing Qt in your program. You should even be able to compile the minimal program with just gcc file.c and then run the executable (a.out), so not even using anything Qt to build.

    Try compiling for Release versus Debug, does that make any difference? Try running your executable from the command-line, not from Qt Creator, does that make any difference?



  • @JonB
    From a build folder it runs good.
    Non-debug run - also good.
    It happens only in Debug run.



  • @jenya7
    For your test program you don't need anything Qt. Remove all those QT += core-type lines from .pro file. Runs OK from command-line, outside Creator? Errors only when run inside Creator? From Creator, when you run it have you tried both "Run without debugging" and "Run with debugger"?



  • @jenya7 said in Linux application crashes.:

    It happens only in Debug run.

    Try running it under gdb from outside Qt Creator. From a command-line you can just go:

    gdb /full/path/to/executable
    

    and then IIRC type run<RETURN> inside gdb prompt.



  • @JonB said in Linux application crashes.:

    @jenya7 said in Linux application crashes.:

    It happens only in Debug run.

    Try running it under gdb from outside Qt Creator. From a command-line you can just go:

    gdb /full/path/to/executable
    

    and then IIRC type run<RETURN> inside gdb prompt.

    This way it runs good.



  • @jenya7
    So if this is all true, and you have tried the various suggestions for within Creator, it looks like there is some problem when Creator invoked gdb, doesn't it?

    I don't know what is wrong. You could check your version of Creator is up-to-date. And that the kit is running the desired gdb executable. I suppose you might try uninstalling and reinstalling Creator, just in case. Until someone else posts a better solutuon.



  • @JonB
    An old project runs good in Debug run.



  • @jenya7
    Then create a brand new tiny test project from scratch and try that. If that works, go back to existing project and delete everything from the build output directory, run qmake and re-build, maybe that will clear it up?



  • Very peculiar. If I create a widget app - all is good, it runs in Debug. A console app just created, no files or libs added - generates the problem.


Log in to reply