Hi all!

I am getting compile errors when it is Linking.

--------------------Configuration: CIRCLE - Win32 Debug--------------------
Compiling...
circle.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/CIRCLE.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

CIRCLE.exe - 2 error(s), 0 warning(s)

# include <iostream.h>

class CCircle {
public:
	CCircle( float x, float y, float r ) : m_x(x), m_y(y), m_r(r) {}
	~CCircle() {}
	float getArea() { return (3.14159f * m_r * m_r);}
	void setX(float x) { m_x = x; }
	void setY(float y) { m_y = y; }
	void setR(float r) { m_r = r; }
	float getX() {return m_x; }
	float getY() {return m_y; }
	float getR() {return m_r; }
private:
float m_x;
float m_y;
float m_r;
};
 CCircle gblCircle(5.,5.,10.);

 int main(int argc, char *argv[]) {
	 CCircle lclCircle(10.,10.,5.);

	 cout << "global circle area" <<
		 gblCircle.getArea() << endl;
	 cout << "local circle area" <<
		 lclCircle.getArea() << endl;

		gblCircle.setR(20.0);
		lclCircle.setR(15.0);

		 cout << "global circle area" <<
		 gblCircle.getArea() << endl;
	 cout << "local circle area" <<
		 lclCircle.getArea() << endl;

	 return 0;

 }

I am going through the Ketstone learning CD's and this is an example code and it works for the guy on the video, i am sure I typed it in just like he had it. It did have a couple of errors, but I corrected them.

Thanx, BandM :cry:

Dani AI

Generated

This thread shows the classic linker mismatch: the CRT startup being linked expects a Windows GUI entry point (WinMain) while the source defines a normal C/C++ main. As noted, the linker error _WinMain@16 coming from wincrt0.obj means the project is configured as a Win32 GUI app, not a console app — which produces LNK2001 and then LNK1120 for the unresolved symbol(s).

Common fixes and options:

  • Build as a console program: create a "Console Application" project or change the project settings so the linker subsystem is Console (Project → Properties → Configuration Properties → Linker → System → SubSystem = Console (/SUBSYSTEM:CONSOLE)).
  • If the program is intended to be a GUI app, provide the proper entry point: implement WinMain (signature below).
  • Advanced alternative: tell the linker to use the CRT entry that calls main by setting the Entry Point to mainCRTStartup (Linker → Advanced → Entry Point). This is a lower-level tweak and should be used with care because it bypasses some default startup behavior.

Example WinMain signature:

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    // GUI initialization / message loop here
    return 0;
}

Why the symbol looks like _WinMain@16: that is the stdcall decoration — @16 is the byte-count of parameters. If using Unicode builds the expected entry can be wWinMain/wWinMainCRTStartup instead. The easiest, least error-prone approach for code that uses main (like the code posted by ) is to use a Console project; that resolves the error in most cases and is what effectively pointed out. Thanks also to for surfacing the related discussion.

Recommended Answers

All 7 Replies

You're using a Win32 application project when you want a console application project. Win32 applications expect WinMain instead of main.

>Take a look on:http://www.daniweb.com/techtalkforums/thread27267.html
Why did you link to a thread where I gave the exact same answer? Dieter's solution was poor (as stated in that thread), so there's no point in (basically) repeating what I said.

I was posting it before I saw wath you said, and since there are no way of deleting post I dident want a emty post.

You can edit and delete a post within 30 minutes of posting it.

Mkey, I belived that one could only edit, will rember that then :)

Thanks Guy's!

That was it! Funny how one wrong step can make a big difference :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.