SDL_Window* window = nullptr; SDL_Surface* sceenSurface = nullptr; SDL_Surface* imgSurface = nullptr; " /> SDL_Window* window = nullptr; SDL_Surface* sceenSurface = nullptr; SDL_Surface* imgSurface = nullptr; " /> SDL_Window* window = nullptr; SDL_Surface* sceenSurface = nullptr; SDL_Surface* imgSurface = nullptr; "/>

winmain problem but I both saved and have the files

28 views Asked by At
#include "SDL/include/SDL.h"
#include <stdio.h>

SDL_Window* window = nullptr;
SDL_Surface* sceenSurface = nullptr;
SDL_Surface* imgSurface = nullptr;

bool init(){
    bool flag = true;
    if (SDL_Init(SDL_INIT_VIDEO)<0){
        printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
        flag = false;
    } else{
        sceenSurface = SDL_GetWindowSurface(window);
    }
    return flag;

};
bool loadMedia(){
    bool flag = true;
    imgSurface = SDL_LoadBMP("imgStickMan.bmp");
    if (imgSurface == nullptr){
        printf("Unable to load image %s! SDL_Error: %s\n", "imgStickMan.bmp", SDL_GetError());
        flag = false;
    }
    return flag;
};
void close(){
    SDL_FreeSurface(imgSurface);
    imgSurface = nullptr;

    SDL_DestroyWindow(window);
    window = nullptr;

    SDL_Quit();
};

int main(int argc, char* argv[]){
    if (!init()){
        printf("failed to initialize!\n");
    } else if (!loadMedia()){
        printf("failed to load media!\n");
    } else{
        SDL_BlitSurface(imgSurface, NULL, sceenSurface, NULL);
        SDL_UpdateWindowSurface(window);
        SDL_Event e;
        bool quit = false;
        while (!quit){
            while(SDL_PollEvent(&e)){
                if(e.type == SDL_QUIT) quit=true;
            }
        }
    }
    close();

    return 0;
}

It is a SDL2 application which I got from an sdl2 tutorial. It is supposed to open upp an image of a stickman bmp file. I also had this error yesterday when trying to run sdl2. c++ standard runs just fine. When I run this code I get this error:

undefined reference to `WinMain' collect2.exe: error: ld returned 1 exit status

I have both reinstalled SDL2 and saved files which others said were the problem. Thanks in advance!

Edit: I suspect this to be a linker error. But I don't know how to begin fixing this.

0

There are 0 answers