0

I am trying to open a window using some SDL2 coding. However, every time I try to compile and run the code, visual studio always gives me the same error(s).

Error: 'identifier' : function cannot be overloaded

Here is my code:

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_image.h>
#include <Windows.h>
using namespace std;

const int WIDTH = 800, HEIGHT = 600;

int WinMain(int argc, char* argv[])
{
    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window *window = SDL_CreateWindow("Hello SDL World", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH, HEIGHT, SDL_WINDOW_ALLOW_HIGHDPI);

    // Check that the window was successfully created
    if (NULL == window)
    {
        // In the case that the window could not be made...
        std::cout << "Could not create window: " << SDL_GetError() << std::endl;
        return 1;
    }

    SDL_Event windowEvent;

    while (true)
    {
        if (SDL_PollEvent(&windowEvent))
        {
            if (SDL_QUIT == windowEvent.type)
            {
                break;
            }
        }
    }

    SDL_DestroyWindow(window);
    SDL_Quit();

    return EXIT_SUCCESS;


}

Here is some warnings they gave me in case they matter:

Warning #1: 'WinMain': Must be '_stdcall'

Warning #2: 'APIENTRY': macro redefinition
  • 1
    Possible duplicate of [Why SDL defines main macro?](https://stackoverflow.com/questions/11976084/why-sdl-defines-main-macro) – UnholySheep Nov 30 '18 at 20:13

1 Answers1

0

Warning #1: 'WinMain': Must be '_stdcall'

Use int main(int argc, char* argv[]) instead. More details here.

Warning #2: 'APIENTRY': macro redefinition

Remove #include <Windows.h>, you don't seem to need it.

(If you do need it, try placing it above other includes. Alternatively, try adding #undef APIENTRY before #include <Windows.h>. )

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207
  • I've tried your suggestions. So I have some good news and bad news; The good news is that i'm not getting that error anymore so that is pretty cool I guess, the bad news is that now i am getting this new error called Error: Entry Point must be defined, know what I should try next? – Derek Byers Dec 01 '18 at 04:18
  • 1
    @DerekByers Did you link `SDL2main.lib` as desribed [here](https://www.libsdl.org/tmp/SDL/VisualC.html)? – HolyBlackCat Dec 01 '18 at 08:05
  • Ya, I linked it in the "Project Name"--------> Properties--------> Linker-------> Input--------> Additional Dependencies – Derek Byers Dec 02 '18 at 02:20
  • I used to be able to code the window with OpenGLand it worked perfectly fine too. Until I downloaded and installed SDL, ever since then I have been getting these errors all of a sudden and I don't quite know why. – Derek Byers Dec 02 '18 at 03:53
  • Does anyone have any idea what to do? Please respond if so. – Derek Byers Dec 07 '18 at 19:10