Nuwen mingw sdl2 undefined reference to sdl_main

Hi guys

I’ve done a good bit of googling and so far I have had no luck finding a solution. I’m using a cli version of the the nuwen mingw port (ver 16.1) on windows 10 and am always getting the undefined reference to sdl_main no matter what I try. My makefile is:

CC=g++
CFLAGS = -std=c++17 -Wall
SOURCES = simple.cpp
TARGET = simple.exe
INCLUDES = -IC:\MinGW\x86_64-w64-mingw32\include
#INCLUDES = -IC:\MinGW\i686-w64-mingw32\include
LIBS = -LC:\MinGW\x86_64-w64-mingw32\lib
#LIBS = -LC:\MinGW\i686-w64-mingw32\lib
LFLAGS = -lmingw32 -lSDL2main -lSDL2

test.exe: $(SOURCES)
$(CC) $(SOURCES) $(INCLUDES) $(LIBS) $(CFLAGS) $(LFLAGS) -o $(TARGET)

run : $(TARGET)
$(TARGET)

.PHONY : clean
clean :
del $(TARGET)

and my cpp file is:

#include <SDL2/SDL.h>
#include

using namespace std;

const int screen_width = 640,
screen_height = 480;
int main(int argc, char argv[]) {
SDL_Window window = NULL;
SDL_Surface
screenSurface = NULL;

if(SDL_Init(SDL_INIT_VIDEO) < 0) {
std::cout << "Couldn’t initialise SDL video : " << SDL_GetError() << endl;
}
else {
window = SDL_CreateWindow(“Simple SDL2”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, SDL_WINDOW_SHOWN);
if(window == NULL) {
std::cout << "Window could not be created : " << SDL_GetError() << endl;
}
else {
//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
//Update the surface
SDL_UpdateWindowSurface( window );
//Wait two seconds
SDL_Delay( 2000 );
}

}

//Destroy window
SDL_DestroyWindow( window );
//Quit SDL subsystems
SDL_Quit();

return EXIT_SUCCESS;
}

The exact error message I get is

g++ simple.cpp -IC:\MinGW\x86_64-w64-mingw32\include -LC:\MinGW\x86_64-w64-mingw32\lib -std=c++17 -Wall -lmingw32 -lSDL2main -lSDL2 -o simple.exe c:/mingw/bin/…/lib/gcc/x86_64-w64-mingw32/8.2.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: C:\MinGW\x86_64-w64-mingw32\lib/libSDL2main.a(SDL_windows_main.o): in function main_getcmdline': /Users/valve/release/SDL/SDL2-2.0.9-source/foo-x64/../src/main/windows/SDL_windows_main.c:175: undefined reference toSDL_main’ collect2.exe: error: ld returned 1 exit status make: *** [Makefile:12: test.exe] Error 1

any ideas as to what the issue may be?

Hi Guys

I seem to have found the solution for my case at least. It seems I had to change the main function to

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

Not sure why but now no errors and runs