1

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.

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
Kaliber64
  • 586
  • 1
  • 5
  • 16
  • It doesn't complain about `main`, it complains about `WinMain` - do you have *that* defined somewhere and linked in? – YePhIcK Jul 28 '12 at 08: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. – Kaliber64 Jul 28 '12 at 08:47
  • Demo you say? Can we download that somewhere and have a look? – Mr Lister Jul 28 '12 at 09:38
  • 1
    @DavidMaloy If it's a SDL app, take a look [here](http://stackoverflow.com/questions/8673378/compiling-with-int-mainvoid-fails-mainint-argc-char-argv-succeeds-why/8673825#8673825). Another possibility is that you don't link with SDLmain. – jrok Jul 28 '12 at 10:36
  • Thanks I needed mingw32 in the linker. – Kaliber64 Jul 29 '12 at 15:38

3 Answers3

4

Use -lSDLmain and -mwindows while linking.

aib
  • 45,516
  • 10
  • 73
  • 79
  • 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. – Kaliber64 Jul 29 '12 at 15:35
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.

Kaliber64
  • 586
  • 1
  • 5
  • 16
-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 :-)

Christian Stieber
  • 9,954
  • 24
  • 23
  • This does not apply to mingw. if not specified explicitly, mingw uses `main` as entry point. – Lol4t0 Jul 28 '12 at 11:10
  • @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 Jul 28 '12 at 11:22
  • @rubenvb, what `gcc` version do you use? `4.7.0` uses `main` even with `-mwindows`. Also [manual page](http://linux.die.net/man/1/gcc) does not state any entry point change. – Lol4t0 Jul 28 '12 at 11:31
  • @Lol4t0 I use MinGW-w64 GCC and I get undefined references to WinMain when using `-mwindows`: http://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 Jul 28 '12 at 12:56
  • @rubenvb, seems to be a bug in `mingw64` due to 3.6.1 of C++ standard. – Lol4t0 Jul 28 '12 at 13:56
  • @Lol4t0 nope. That's `-mwindows`, for compatibility with MS Visual C++ GUI programs. Leave it out, and you get strict standards conformance. MinGW and MSVC have exactly the same behaviour (the latter with the `/SUBSYSTEM` switch as described in the answer above). – rubenvb Jul 28 '12 at 14:16
  • @rubenvb, subsytem switch used not only for `MSVS` compatibility, it also points, whether console should/should not be allocated. You _have to use_ `-mwindows` (or -Wl,--subsystem,windows) in GUI application to hide console. (Also interesting, does `-Wl,--subsystem,windows` also requires `WinMain` on x64? (can't check by myself). – Lol4t0 Jul 28 '12 at 14:28
  • @Lol4t0 I know that. You can hide the console without changing the subsystem though, by linking to other CRT files. My point still stands. – rubenvb Jul 28 '12 at 14:33
  • I needed mingw32 at the top of the linker! sorry for the confusing and thanks for the help! This solution was nowhere. I remembered I used it in the past for reasons unknown. It came with another demo unrelated some time ago. Yay for random guess. – Kaliber64 Jul 29 '12 at 15:37