fatal error LNK1120: 9 unresolved externals

CODE:
hello.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// include the basic windows header file
#include <windows.h>
#include <windowsx.h>

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
                         UINT message,
                         WPARAM wParam,
                         LPARAM lParam);

// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    // the handle for the window, filled by a function
    HWND hWnd;
    // this struct holds information for the window class
    WNDCLASSEX wc;

    // clear out the window class for use
    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    // fill in the struct with the needed information
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = L"WindowClass1";

    // register the window class
    RegisterClassEx(&wc);

    // create the window and use the result as the handle
    hWnd = CreateWindowEx(NULL,
                          L"WindowClass1",    // name of the window class
                          L"Our First Windowed Program",   // title of the window
                          WS_OVERLAPPEDWINDOW,    // window style
                          300,    // x-position of the window
                          300,    // y-position of the window
                          500,    // width of the window
                          400,    // height of the window
                          NULL,    // we have no parent window, NULL
                          NULL,    // we aren't using menus, NULL
                          hInstance,    // application handle
                          NULL);    // used with multiple windows, NULL

    // display the window on the screen
    ShowWindow(hWnd, nCmdShow);

    // enter the main loop:

    // this struct holds Windows event messages
    MSG msg;

    // wait for the next message in the queue, store the result in 'msg'
    while(GetMessage(&msg, NULL, 0, 0))
    {
        // translate keystroke messages into the right format
        TranslateMessage(&msg);

        // send the message to the WindowProc function
        DispatchMessage(&msg);
    }

    // return this part of the WM_QUIT message to Windows
    return msg.wParam;
}

// this is the main message handler for the program
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // sort through and find what code to run for the message given
    switch(message)
    {
        // this message is read when the window is closed
        case WM_DESTROY:
            {
                // close the application entirely
                PostQuitMessage(0);
                return 0;
            } break;
    }

    // Handle any messages the switch statement didn't
    return DefWindowProc (hWnd, message, wParam, lParam);
} 


BUILD LOG:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
1>Compiling...
1>hello.cpp
1>Linking...
1>hello.obj : error LNK2019: unresolved external symbol __imp__PostQuitMessage@4 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
1>hello.obj : error LNK2019: unresolved external symbol __imp__DefWindowProcW@16 referenced in function "long __stdcall WindowProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WindowProc@@YGJPAUHWND__@@IIJ@Z)
1>hello.obj : error LNK2019: unresolved external symbol __imp__TranslateMessage@4 referenced in function _WinMain@16
1>hello.obj : error LNK2019: unresolved external symbol __imp__DispatchMessageW@4 referenced in function _WinMain@16
1>hello.obj : error LNK2019: unresolved external symbol __imp__GetMessageW@16 referenced in function _WinMain@16
1>hello.obj : error LNK2019: unresolved external symbol __imp__ShowWindow@8 referenced in function _WinMain@16
1>hello.obj : error LNK2019: unresolved external symbol __imp__CreateWindowExW@48 referenced in function _WinMain@16
1>hello.obj : error LNK2019: unresolved external symbol __imp__RegisterClassExW@4 referenced in function _WinMain@16
1>hello.obj : error LNK2019: unresolved external symbol __imp__LoadCursorW@8 referenced in function _WinMain@16
1>C:\Users\Toby Hinloopen\Documents\Visual Studio 2005\Projects\Project1\Debug\Project1.exe : fatal error LNK1120: 9 unresolved externals
1>Build log was saved at "file://c:\Users\Toby Hinloopen\Documents\Visual Studio 2005\Projects\Project1\Project1\Debug\BuildLog.htm"
1>Project1 - 10 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


USING:
VC++ 2005 express edition
with
windows SDK server 2008
on
windows vista HP 32bit

Whats the problem here?
Why doesn't it compile like it should?

It should compile correctly, since the sourcecode is from http://www.directxtutorial.com/Tutorial9/A-Win32/dx9A3.aspx


2009 doesn't start well...
still compiling problems.
Last edited on
This is not linking correctly with the user32.lib library.

In the project properties, in the linker part, check the CommandLine - this shows what parameters/options the linker will be using and should look something like this:
/OUT:"C:\Documents and Settings\andy\My Documents\Programming\Projects\msvc\testing_001\Debug\testing_001.exe"
/INCREMENTAL /NOLOGO /MANIFEST /MANIFESTFILE:"Debug\testing_001.exe.intermediate.manifest"
/MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"c:\Documents and Settings\andy\My Documents\Programming\Projects\msvc\testing_001
\Debug\testing_001.pdb"
/SUBSYSTEM:CONSOLE /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT
kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib
shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


What libraries does it show are being linked in?
/OUT:"C:\Users\Toby Hinloopen\Documents\Visual Studio 2005\Projects\Project1\Debug\Project1.exe" /NOLOGO /MANIFEST /MANIFESTFILE:"Debug\Project1.exe.intermediate.manifest" /ERRORREPORT:PROMPT kernel32.lib
hmm, doesn't look like yours :P
i'm trying your command line

edit: crap, i cannot edit it :P

what to do know?
Last edited on
No you can't edit that.
That is just a display of all your linker options you have selected.


Try this first:
Linker -> Input and in the Additional Dependencies add the names
of the missing libraries seperated by spaces. For example user32.lib gdi32.lib --- or you can use use the ... button which will bring up a bigger edit box where you can enter the names (one per line).

Whooohooo, it works :)

Now, how can i set both:

-Characterset
and
-Linker -> Input

with default settings?

i don't want to set Charset @ unicode and linker @ user32.lib every time i start a new project... it should be possible to default that, but how?
I don't know what when wrong when your project settings - but I'm sure that Visual Studio should default to Unicode Character set, and it should set itself up to link all those libs we saw earlier, each time you create a new project.
Topic archived. No new replies allowed.