   Linking Error
  I got a linking errorLinking...LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _mainDebug/d9_test.exe : fatal error LNK1120: 1 unresolved externalsError executing link.exe.What does that mean?Well, I just want to make a simplist window.Codes as below:#define WIN32_LEAN_AND_MEAN#include "windows.h"HINSTANCE hInstance;HWND hWnd;bool initwindow(HINSTANCE hInstance);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTRlpCmdLine, int  nCmdShow){if (!initwindow(hInstance))return false;MSG msg;ZeroMemory(&msg, sizeof(msg));while(msg.message != WM_QUIT){while(GetMessage(&msg, hWnd, 0, 0)){TranslateMessage(&msg);DispatchMessage(&msg);}}return 0;}bool initwindow(HINSTANCE hInstance){WNDCLASSEX wcex;wcex.cbSize = sizeof(WNDCLASSEX);wcex.style = CS_HREDRAW|CS_VREDRAW;wcex.lpfnWndProc = (WNDPROC)WndProc;wcex.cbClsExtra = 0;wcex.cbWndExtra = 0;wcex.hInstance = hInstance;wcex.hIcon = 0;wcex.hIconSm = 0;wcex.hCursor = LoadCursor(NULL, IDC_ARROW);wcex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;wcex.lpszMenuName = NULL;wcex.lpszClassName = "WndClass";RegisterClassEx(&wcex);hWnd = CreateWindow("WndClass", "Hello World", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);if (!hWnd)return false;ShowWindow(hWnd, SW_SHOW);UpdateWindow(hWnd);return true;}LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){switch(message){case WM_DESTROY:PostQuitMessage(0);break;}return DefWindowProc(hWnd, message, wParam, lParam);}
  Odds are you have created a "Console application" project, which expects a main() function, rather than a "Windows application" project, which uses a WinMain() function.   ;  Your program builds as a console (text-mode) program, so the compiler looks for the entry point for the console subsystem, which is main.If you want to make a windows program, you need to choose the windows subsystem.You have two choices:1. Go through the project settings until you found the switch for changing to windows subsystem2. Recreating your project, specifying the win32 project type, and dropping in all your files again.HTH, Konfu   ;  ...Fruny. Of course. Why did I even try? :P;  Oh~, got it.Thanks, you saved my soul.Well how do you know that?I mean what shows that I created a project in Console Mode?   ;unresolved external symbol _mainThis linker error means something likeI can not find the main function...So we know that the linker is trying to find a main function and not a WinMain function.This is an indication that you have set up a console application.   ;  The linker error: 'unresolved external symbol _main' means that the compiler is looking for a symbol by the name 'main' and can't find it anywhere.  Now, when you program a console application you must ALWAYS have a main function.  Because you have windows code we know the compiler shouldn't be looking for main at all.  Thus we can deduce that you set your compiler to console mode by mistake.This is a very common mistake that people make too, so that helps.The other time you may recieve this error is when having multiple files in your project.  For instance, say you have these files(c++, not sure if you're in C or C++):header.h#ifndef HEADER_H_#define HEADER_H_int foo(float bar);int bar(float foo);#endifheader.cpp#include "header.h"int bar(float foo){  return foo*10;}main.cpp#include <iostream>#include "header.h"using namespace std;int main(){  cout << foo(5) << endl;  cout << bar(5) << endl;  return 0;}This code should create an unresolved external error relating to foo.   ;  Thank you all.It's really fantastic.Still lots of things I should learn standing ahead.   ;  Oh, to add a bit of explanation to the above code: in header.h you see two function prototypes.  These tell the compiler that SOMEWHERE, eventually, in some file, you will find two functions called foo and bar that both take a float and return an int.  That can also be called the function decleration.  Remember, the absolutely only thing the decleration does is promise the compiler the code will come later.In header.cpp we have to say what the function does.  We 'define' what the function does with the code, hence we say that this is the function definition.  the function bar is defined, but not the function foo.in main.cpp we call both functions.  when the compiler encounters the function call to foo, it looks to the first place it finds a reference to foo in the code, and sees the function definition int foo(float bar);.The compiler does the same thing in header.cpp.  It compiles the code, checking for any unknown symbols and trying to find out the definiton.  The definition tells the compiler how the code will look whne you call the function, but not where to jump or what the code you call does.Finally, when all the files are done compiling, the compiler links them all together, sorting out all the symbols we promised would appear SOME place.  First the compiler looks in main.o and sees you use the symbols 'std' (Actually I think the compiler deals with the std symbol in the compiling phase, but whatever), 'main', 'cout', 'foo', 'endl', and 'bar'.  main is the special entryway into the program so the compiler puts that function into the right place in the executable data file.  The code dealing with cout is found somewhere in the standard library files.  the code for foo is found... wait, it isn't found!  "You fool!", the compiler says, "what am I supposed to do now?  You PROMISED me you'd define that function.  Okay, I'm very angry with you, but I'm busy.  Remember though, this issue is not resolved!"  Then the compiler looks for endl, finds it in the library.  Finally, finds bar in header.oAnd there you have it, linking 101.  I think that's at least 95% correct.   