0

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;
}
5
  • make sure you don't have main inside a namespace. And link against -lmingw32 Commented Apr 4, 2013 at 17:03
  • try this link: (you may tried already) wiki.libsdl.org/moin.fcg/FAQWindows Commented Apr 4, 2013 at 17:04
  • I went to the linker settings in Code::blocks and under "Other linker options" I put "-lmingw32 -lSDLmain -lSDL -mwindows", but I still get the error. Commented Apr 4, 2013 at 17:16
  • Have you looked here? stackoverflow.com/questions/5259714/… Commented Apr 4, 2013 at 17:19
  • Yes, but I'm using the GNU compiler and the -mwindows flag. Commented Apr 4, 2013 at 17:22

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.