Skip to content

Segmentation fault when compile with MinGW #495

@aregtech

Description

@aregtech

Description:
When compile applications with the GNU compile under MinGW installed with Qt 6.8, many applications crash when called printf() and the message indicates segmentation fault. For example, the example project 05_timer crashes and the debugger indication this call stack:

Qt-Creator screenshot

To Reproduce
Steps to reproduce the behavior.
Precondition:

  • Install Qt 6.8 and install MinGW deployed with the Qt installer;
  • Clone the sources from branch feature/494-compile-with-mingw, which is adapted to compile with MinGW. The main branch will not be compiled with MinGW.

Actions:

  1. Select example project 05_timer as the Startup project;
  2. Start debugging.

Result:
Shortly the application is crashing with Segmentation Fault message and the callstack indicates printf() method. See the screenshot.

Expected behavior
You can as well reproduce the same behavior with the simple `printf("Hello World!") project. To do so,

  1. Manually create a directory, for example hello, somewhere in the areg-sdk. To simplify, let's create in the framework directory a hello sub-directory.
  2. Create a file hello.cpp with the following content:
    #include <stdio.h>
    int main(int argc, char* argv[], char* envp[])
    {
        printf("Hello World!");
        return 0;
    }
  3. In the same hello sub-directory create a CMakeLists.txt file with the following content:
    add_executable(hello "${AREG_FRAMEWORK}/hello/hello.cpp")
    target_compile_definitions(hello PRIVATE ${COMMON_COMPILE_DEF})
    target_compile_options(hello PRIVATE "${AREG_OPT_DISABLE_WARN_TOOLS}")
    target_include_directories(hello BEFORE PRIVATE ${CMAKE_CURRENT_LIST_DIR})
    target_link_options(hello PRIVATE -mwin32 -municode -mconsole)
    target_link_libraries(hello areg aregextend ${AREG_LDFLAGS} )
  4. Modify CMakeLists.txt file located in the framework directory, include new created project in the last line
    include("${AREG_FRAMEWORK}/hello/CMakeLists.txt")
  5. Open Qt-Creator ==> open areg-sdk directory ==> configure projects ==> build
  6. When all projects are compiled without error, you'll see hello.exe among other binaries.
  7. In the Qt-Creator select hello project as the startup project and start with debugger. Additionally, you can set a breakpoint at the line printf("Hello World!");
  8. As soon as the program hits the printf() you'll see the following dialog and the debugger callstack pointing to the printf() method.

SIGSEGV message

Note

The application runs without a problem is you remove aregextend library from this line target_link_libraries(hello areg aregextend ${AREG_LDFLAGS} ) in the CMakeLists.txt file.

Desktop or embedded (please complete the following information):

  • OS: Windows 11
  • Hardware: AMD64
  • Compiler: g++ for MinGW-64
  • AREG SDK version: feature/494-compile-with-mingw branch

Additional context
The projects in examples are compiled with the same flags and options. The projects 01_hello, 02_buffer, 03_file, 04_logging run without a problem. The project 05_timer is crashing with the same SIGSEGV signal.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions