Kaliber64
Kaliber64

Reputation: 594

undefined reference to `WinMain@16'?

I looked at other solutions but I don't know why it says this because I have a main. I have tried building as a console app and GUI app. It's suppose to be a GUI app(SDL). Does there have to be a main anywhere in the header files? For what reason would you have a main and main is not found.

After 35 hours I finally think that this is the last error.

My IDE is Code Blocks, my compiler is MinGW32.

Upvotes: 0

Views: 5224

Answers (4)

99o99u
99o99u

Reputation: 11

I had the same issue and I had been having this for quite some time. I decided to look into it and it turns out that that is just something the SDL does. In the SDL2_main.h file, there is a #define main SDL_main which causes your main function to act differently. You can go into the SDL_main.h file and fix it if it bothers you too much. Even commenting it out will "fix" it but it may cause problems in some later phase. Generally using a different version of SDL2 may help you best. (Haven't tried this though)

Else, you can just use WinMain() in place of main(). It will act as a temporary fix and the compiler will throw out a warning but use that if you really want to run the program.

Upvotes: 1

Kaliber64
Kaliber64

Reputation: 594

I put mingw32 at the top of the linker and then I could use regular main. I had winmain working after I included windows.h and got all the extra args. But I deleted it for something simpler.

Upvotes: 0

aib
aib

Reputation: 46921

Use -lSDLmain and -mwindows while linking.

Upvotes: 4

Christian Stieber
Christian Stieber

Reputation: 12496

WinMain is one of the possible entry points for a program.

I'm not familar with GCC on Windows, or "CodeBlocks". The /ENTRYPOINT linker option of the Microsoft linker describes the possible entry points: http://msdn.microsoft.com/en-us/library/f9t8842e%28v=vs.110%29

As you can see, "main" is used for a non-unicode console app, whereas WinMain is used for a non-unicode GUI app.

On the Microsoft linker, the /SUBSYSTEM option is used to decide what kind of app you are building.

Chances are that

  • you have to do something like /SUBSYSTEM for your compiler, or
  • you have to link with some compiler-specific library

Maybe you can figure out what to do given the above hints :-)

Upvotes: -1

Related Questions