undefined reference to `WinMain@16'

I've seen this discussed in various topics but none are active for replies so I'm posting here.

I experienced this link error using Eclipse IDE for C/C++ Developers on Windows 7. Under Properties I had this configuration
C/C++ Build Tool Chain Editor  Current toolchain: MinGW GCC
C/C++ Build Tool Chain Editor Current Builder: CDT Internal Builder

I used the IDE to create the Class files (.cpp aand .h). The mistake I made, which caused my error was I put main() inside the automatically generated block - namespace std { ... }. Outside, I don't get the "undefined reference to `WinMain@16'" error. Easy to see now why it didn't find the entry point.

#include "A.h"

namespace std {

A::A() {
// TODO Auto-generated constructor stub


A::~A() {
// TODO Auto-generated destructor stub


int main( int argc, char** argv ){ // << inside namespace std causes the error
return 0;

} /* namespace std */
You should not be defining stuff in the std:: namespace.
Removing the namespace std {will fix this issue. The compiler looks for int main(int, char**) to run. You are supplying it with int std::main(int, char**).

Most likely you meant using namespace std; rather than namespace std {. The first will allow you to access members of std, but the second will run all your code as a member of std.
Last edited on

I think I see what happened here.

Eclipse has a rather handy feature of allowing one to specify a namespace for a new class in the class wizard.

This is a really good idea, because one should put their own classes into their own namespace(s) to keep them out of the std namespace.

I have 4 IDE's running under Linux now KDevelop, QtCreator, Eclipse & CodeBlocks, and Eclipse is the only one with this feature.

With the using namespace std; it would be better if you didn't have that - just put std:: before each std thing.

Any way Good Luck !!
Topic archived. No new replies allowed.