SDL2 compiles but doen't open a window when run

I try to setup a SDL2 project on Eclipse (on mac) for a class project.

I followed this video tutorial “”.

I tried the following code and I have no errors but the window doesn’t open, there is just the icon of a “ghost” program that opens (as in the picture below). I searched for a solution on the internet but impossible to find something about it …

Someone would have already encountered this problem ?

[Testing code]

#include <stdio.h>
#include <SDL2/SDL.h>

int main(int argc, char** argv)
    if (SDL_Init(SDL_INIT_VIDEO) != 0 )
        fprintf(stdout,"Failed to initialize the SDL (%s)\n",SDL_GetError());
        return -1;

        SDL_Window* pWindow = NULL;
        pWindow = SDL_CreateWindow("My first SDL2 application",SDL_WINDOWPOS_UNDEFINED,

        if( pWindow )

            fprintf(stderr,"Error creating the window: %s\n",SDL_GetError());


    return 0;

[The “ghost” program]

On MacOS, you have to pump the message/event queue before the window will be shown. In an actual application this isn’t a problem, since you’re going to have to do it to get input etc., but in a toy application where you’re just trying to show a window, you’ll need to add something like

if(pWindow) {
    // Go through the pending event queue once
    SDL_Event event;
    while(SDL_PollEvent(&event) {
        // do nothing



1 Like

Thank you very much for the explanation! Now it works perfectly :pray: