0

I am at a loss as to why I am getting this error:

test_project.obj : error LNK2019: unresolved external symbol "int __cdecl run(void)" (?run@@YAHXZ) referenced in function _WinMain@16

code is as follows:

            #include "stdafx.h"
            #include "test_project.h"
            #include <Windows.h>

            HWND ghMainWnd = 0;

            bool InitWindowsApp (HINSTANCE instanceHandle, int show);

            int run();

            LRESULT CALLBACK
            WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

            int WINAPI
            WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int nShowCmd) {
                if (!InitWindowsApp (hInstance, nShowCmd) )
                    return 0;
                return run();
            }

            bool InitWindowsApp (HINSTANCE instanceHandle, int show) {
                WNDCLASS wc;
                wc.style        = CS_HREDRAW | CS_VREDRAW;
                wc.lpfnWndProc  = WndProc;
                wc.cbClsExtra   = 0;
                wc.cbWndExtra   = 0;
                wc.hInstance    = instanceHandle;
                wc.hIcon        = LoadIcon( 0, IDI_APPLICATION );
                wc.hCursor      = LoadCursor( 0 , IDC_ARROW );
                wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
                wc.lpszMenuName = 0;
                wc.lpszClassName = L"BasicWndClass";

                if (!RegisterClass(&wc) ) {
                    MessageBox(0, L"RegisterClass FAILED", 0, 0);
                    return false;
                }

                ghMainWnd = CreateWindow (
                    L"BasicWndClass",
                    L"Win32Basic",
                    WS_OVERLAPPEDWINDOW,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    0,
                    0,
                    instanceHandle,
                    0);

                if (ghMainWnd == 0) {
                    MessageBox ( 0, L"CreateWindow FAILED", 0, 0);
                    return false;
                }
                ShowWindow (ghMainWnd, show);
                UpdateWindow (ghMainWnd);

                return true;
            }

            int Run() {
                MSG msg = {0};

                BOOL bRet = 1;
                while ((bRet = GetMessage(&msg, 0, 0, 0)) != 0) {
                    if (bRet == -1)
                    {
                        MessageBox(0, L"GetMessage FAILED", L"Error", MB_OK);
                        break;
                    }
                    else {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
                    }
                }
                return (int)msg.wParam;
            }

            LRESULT CALLBACK
            WndProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
                switch(msg) {
                case WM_LBUTTONDOWN:
                    MessageBox(0, L"Hello, World", L"Hello", MB_OK);
                    return 0;
                case WM_KEYDOWN:
                    if (wParam == VK_ESCAPE)
                        DestroyWindow(ghMainWnd);
                    return 0;
                case WM_DESTROY:
                    PostQuitMessage(0);
                    return 0;
                }

                return DefWindowProc (hWnd, msg, wParam, lParam);
            }

In the property pages->c/c++->general->additional include directories I have put the directory containing the lib: C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib

In property pages->linker->input->additional dependencies I have put the full path to the lib C:\Program Files\Microsoft SDKs\Windows\v7.1\Lib\user32.lib

In property pages->linker->system->subsystem I have put Windows (/SUBSYSTEM:WINDOWS)

I am at a loss as to what to try next.

r m
  • 177
  • 13

1 Answers1

1

C++ is case-sensitive. You have to decide whether to name your function run() or Run().

int run();

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
                   PSTR pCmdLine, int nShowCmd) {
    if (!InitWindowsApp (hInstance, nShowCmd) )
        return 0;
    return run();  // <-- There.
}

Versus:

int Run() {
    // ...
}
Community
  • 1
  • 1
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479