FrederickEason
FrederickEason

Reputation: 1

Code::Blocks, MinGW, libsdl, and GNU C++ compiler: undefined reference to `WinMain@16

I have been trying to compile the most basic SDL application, but no matter what I do I keep getting this error:

c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'

I searched for solutions for this, but they all had to do with either Visual C++ or a missing main. I am not using Visual C++, and I have defined main.

Here's my code:

#include "SDL/SDL.h"

int main( int argc, char* args[] )
{
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );

    //Quit SDL
    SDL_Quit();
    return 0;
}

Upvotes: 0

Views: 6213

Answers (3)

user2863598
user2863598

Reputation: 1

I encountered the same error in a project of mine that I want to compile both on linux and windows. I use a makefile to compile the project. A solution that has worked for me, although I admit it is a bit of a hack is adding this to main.cpp (wherever your main function would be)

extern "C" {

    int WinMain(int argc, char** argv)
    {
        return main(argc, argv);
    }
}

This makes the linker find WinMain and use it as the entry point in the program. I can also hope that this solution doesn't break linux compilability, hopefully it will be considered just an unused function.

Upvotes: 0

Austin Salgat
Austin Salgat

Reputation: 415

In case someone else comes across this, I put -lmingw32 after -lSDLmain and -lSDL which caused this issue for me. Putting -lmingw32 first fixed it.

Upvotes: 0

TheBuzzSaw
TheBuzzSaw

Reputation: 8826

Don't use "Other linker options". Use the "Link libraries" section. Add the following items.

mingw32
SDLmain
SDL

You can put -mwindows in the "Other linker options" section.

Upvotes: 6

Related Questions