View Full Version : error LNK2001; error LNK1120

03-24-2006, 02:44 AM
hi guys...

two days ago everything went good.. but today .. i compiled my Win32 application and wanted to execute the main.exe file..

suddlenly my comiler wrote 2 errors!

error LNK2001; error LNK1120 well.. usually you have to change the settings of the linker.. you have to change /subsystem:windows to /subsystem:console

well.. i did it.. but the same error was written..

can anyone help me?

in the source code there arent any mistake, i know that because the last time i executed that file everything was right...

does anyone know whats going on? :(

03-24-2006, 03:37 AM
well.. here is the source code...

#include <windows.h>

case WM_CLOSE: DestroyWindow(hwnd);
case WM_DESTROY: PostQuitMessage(0);
return DefWindowProc(hwnd, msg, wParam, lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
LPCTSTR className = "ClassName";

// ..........................................

wc.cbSize = sizeof(WNDCLASSEX); //Spezifiziert die Größe der Struktur und sollte immer auf sizeof(WNDCLASSEX) gesetzt werden
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); //Der Icon der ganz links oben beim Fenster angezeigt wird
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = className;
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

MessageBox(NULL, "Error registering class", "Error", MB_OK | MB_ICONERROR);
return 1;

HWND hwnd = CreateWindowEx(0, className, "05 - Creating Windows", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 300, 300, NULL, NULL, hInstance, NULL);

MessageBox(NULL, "Error creating window", "Error", MB_OK | MB_ICONERROR);
return 1;

ShowWindow(hwnd, nShowCmd);

MSG msg;

while(GetMessage(&amp;msg, NULL, 0, 0) > 0 )

return (int)msg.wParam;

03-24-2006, 05:49 AM
What is the name of unresolved external symbol that linker reports?

Did you opened the same project or did you use the same source file in another project?

Have you tried complete rebuild?

03-24-2006, 10:07 AM
What is the name of unresolved external symbol that linker reports?

Did you opened the same project or did you use the same source file in another project?

Have you tried complete rebuild? well.. the message is:

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/main.exe : fatal error LNK1120: 1 unresolved externals Error executing

i didn't opened an old project and i didn't used one file in another project. i just wrote the same program again i wrote before (i'm learning ^^) ..

yes, i've tried a complete rebuild.. with the same result ...

i red on another page that i only have to change the linker settings .. instead of /subsystem: windows i should write /subsystem: console.. the first time i did it everything went good..

but now .. :(

i don't know whats going on..

another page said if the fault appears even though i have changed the settings to /subsystem: console it could be that the compiler has a fault. if this happens i should write all commands into the main() function..

well... i think this is impossible, isn't it?

03-27-2006, 12:10 AM
Your source code has a WinMain not a main function so it should be a windows application, (subsystem:windows) if you do have a main function you can use subsystem:console

So if you get an unresolved external for _main you have linked with subsystem:console (require a main function) or you have messed up the library dependencies so that the builtin _main is not available.

03-29-2006, 06:55 AM
Which IDE/Compiler are you using ? This may help to understand if you probably choosed a console subsystem and you coded a WinMain inside. (i.e. Visual Studio console subsystem is called console application, and win32 application with the windows subsystem)