0

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.

5
  • It doesn't complain about main, it complains about WinMain - do you have that defined somewhere and linked in? Commented Jul 28, 2012 at 8:39
  • The demo is prewritten for Visual studio for an animation lib I'm using. I worked with the owner of the lib (god bless his help). But he doesn't have the time to fix all my problems. He said it was compiling with the changes he made. He emailed me his changes. There isn't a winmain in any of his demos that come with the lib. I also tried to replace main with winmain, Winmain, WinMain and winMain. None worked. Commented Jul 28, 2012 at 8:47
  • Demo you say? Can we download that somewhere and have a look? Commented Jul 28, 2012 at 9:38
  • 1
    @DavidMaloy If it's a SDL app, take a look here. Another possibility is that you don't link with SDLmain. Commented Jul 28, 2012 at 10:36
  • Thanks I needed mingw32 in the linker. Commented Jul 29, 2012 at 15:38

4 Answers 4

4

Use -lSDLmain and -mwindows while linking.

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

1 Comment

SDL libs are linked but I found that mwindows fix but there was no lib by that name. I needed mingw32 at the top of the linker and I was able to change my winmain back to main.
1

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.

Comments

0

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.

Comments

-1

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 :-)

9 Comments

This does not apply to mingw. if not specified explicitly, mingw uses main as entry point.
@Lol4t0 untrue; if you link with -mwindows the entry point is WinMain. The fact that -mconsole is the default is to be Standard conformant out of the box really...
@rubenvb, what gcc version do you use? 4.7.0 uses main even with -mwindows. Also manual page does not state any entry point change.
@Lol4t0 I use MinGW-w64 GCC and I get undefined references to WinMain when using -mwindows: pastebin.com/Ur6RZbuS It's not so much about entry point as it is about what functions need to be present. With -mwindows, a different CRT file is used (which has main, but expects a user's WinMain). So the entry point might be unchanged, you'd still need a WinMain function.
@rubenvb, seems to be a bug in mingw64 due to 3.6.1 of C++ standard.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.