undefined reference to WinMain@16 with devcpp

Started by
6 comments, last by GameDev.net 18 years, 10 months ago
I am trying to compile a OpenGL program which uses glut. I am using devcpp and I am getting linker error of undefined reference to WinMain@16. I searched around, it seems others have had this kind of problem but few but posted solutions, grrr. Can anyone help me? I know the program should work, I compiled and ran it under linux and it most definitely have a main function decalred: int main(int argc, char *argv[]) I hope this doesn't mean I have to mess around with win32 api. thanks
Just because it is not nice, doesn''t mean it is not miraculous.
Advertisement
Are you building the project as a Win32 GUI? If not, try that -- otherwise there's a certain file I remember having to link with (off the top of my head I'd say mingw32).

Try both of those, and if neither works...sorry, can't help you from here.
Things change.
adding -lmingw32 didn't seem to do anything

now when you says compiling as a Win32 GUI, do you mean choosing windows application under basic when creating a project? As that doesn't seem to set any linker options that would have helped. I have not tried this yet, as it is 4am and I need some sleep.

thanks for the reply
Just because it is not nice, doesn''t mean it is not miraculous.
Dev-C++ has an option under the Project->Project Options menu that will allow you to compile as a Win32 GUI. But again, I'm not completely sure if this will solve your problem or not.

Sorry about the delayed reply, and I'm sure you've gone to sleep, so this won't help until tomorrow, I guess.
Things change.
Assuming Dev-C++ uses MinGW (I think it does)...

On my system, I'm running MinGW's GCC 3.4.2, it appears to auto-detect if main or WinMain is declared, so:

If you've got a malformed main function it can cause this error (read: typeod as mian, that kind of thing). If you didn't copy and paste or directly copy the file, double check you havn't mistyped.

Another thing to try (should work for cygwin too) would be to pass -mconsole to your linker.
If your program is small enough ( < 600 lines?), post the source code. Whatever the problem is, it most likely involves main().

Also, to Boku San: That dot game...........O_O
Well, it works now, using the same setting as before but it gives no errror and runs fine, grr.

I tried all of the solutions suggested, none of it worked, it was only after I reinstalled devcpp (separate issue, I tried to update dev-cpp and it starts giving a whole new bunch of errors I have never seen before) and recreated the project, it nows links without problem. Relieved but still very annoyed.

Thanks for all the helps, much appreciated.
Just because it is not nice, doesn''t mean it is not miraculous.
I was searching answers to the same problem and i came here from google. One of the main problems with glut and the WinMain16 linker reference error always seems to come from the "main" method definition. And indeed it was the case for me, something was wrong with my main function.

Now you see, i'm doing opengl programming in c++, using OOP to make the application. And with c++ comes namespaces. It is a bad idea to make a main function within a namespace. For glut (well, openglut for me) to work (and bloodshed dev c++), the main function musn't be inside a namespace.

Another issue you must take care of when you're doing OOP with glut is that functions wich receive pointers to other functions (such as glutDisplayFunc or glutReshapeFunc) cannot receive some object's method, it must be an outside global function. Frankly speaking, that sucks for me as i wished to do a true OOP application, but...that's the price to pay when one does not master windowing toolkits and has to use glut. I hope QT4 comes out soon, i'm eager to try it, as it ships with opengl support.

That i learned the hard way, and that i wished to share with the community.

I hope this helps anyone with the same problems i had. Good luck to you, and thank you to the previous posters, since without their words i wouldn't have looked upon the "main" function.

This topic is closed to new replies.

Advertisement