'No SDL2 window shown when compile and run

I use DevC++ on Windowss 10 but my problem is that I followed some tutorials about SDL2 in C but when I write the program they give, it compiles well, however I can't see my window. The problem may come from the "searched directories " as I had issues to install SDL2 on DevC++

// Code :

#include <stdlib.h>
#include <stdio.h>
#include <SDL2\SDL.h>


int main(int argc, char* argv[])
{

    SDL_Window *ecran = NULL;
    SDL_Renderer *renderer;

    SDL_Init(SDL_INIT_VIDEO);

ecran = SDL_CreateWindow("DBZ", 0, 0, 640, 480, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(ecran, -1, SDL_RENDERER_ACCELERATED);

SDL_RenderPresent(renderer);

SDL_Delay(30000);
SDL_Quit();


    return EXIT_SUCCESS;
}

Compiling project changes...

  • Project Filename: C:\Users\Anthony\Desktop\programmes\SDL\Premier essai\Projet1.dev
  • Compiler Name: TDM-GCC 4.9.2 64-bit Release

Building makefile...

  • Filename: C:\Users\Anthony\Desktop\programmes\SDL\Premier essai\Makefile.win

Processing makefile...

  • Makefile Processor: C:\Users\Anthony\Desktop\Dev-Cpp\MinGW64\bin\mingw32-make.exe
  • Command: mingw32-make.exe -f "C:\Users\Anthony\Desktop\programmes\SDL\Premier essai\Makefile.win" all

mingw32-make.exe: Nothing to be done for 'all'.

Compilation results...

  • Errors: 0
  • Warnings: 0
  • Output Filename: C:\Users\Anthony\Desktop\programmes\SDL\Premier essai\Projet1.exe
  • Output Size: 298,20703125 KiB
  • Compilation Time: 0,22s


Solution 1:[1]

Maybe your window just creates and immediately closing?. Try replace your SDL_Delay with:

bool quit = false;
mainEvent = new SDL_Event();

while (!quit && mainEvent->type != SDL_QUIT) {
    SDL_PollEvent(mainEvent);
    //...
}

Solution 2:[2]

I had the same problem on Windows; no issues with compilation, but instant exit on run. In my case, I was linking using the x86 rather than x64 binary when attempting to use a 64 bit build rather than a 32 bit build.

To reproduce the problem, I had just adjusted the development library paths, updating them to

CFLAGS = -std=c99 -Wall -pedantic -Werror -I..\SDL2-2.0.14\x86_64-w64-mingw32\include\SDL2 
LFLAGS = -lmingw32 -lSDL2main -lSDL2 -L..\SDL2-2.0.14\x86_64-w64-mingw32\lib

from -I..\SDL2-2.0.14\i686-w64-mingw32\include\SDL2, but hadn't yet replaced the .dll files. After grabbing the x64 binary from the site above, all was well.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 CrishNate
Solution 2 ggorlen