"LNK2001: unresolved external symbol" when trying to build my program

Posted by random on Game Development See other posts from Game Development or by random
Published on 2012-10-29T13:10:41Z Indexed on 2012/10/29 17:26 UTC
Read the original article Hit count: 246

Filed under:
|
|
|

I get the following error(s) on my program that captures the mouse and then draws a line. Errors:

1>------ Build started: Project: Capture_Mouse_Line, Configuration: Debug Win32 ------
1>  main.cpp
1>main.obj : error LNK2001: unresolved external symbol "public: static long * Line::yc2" (?yc2@Line@@2PAJA)
1>main.obj : error LNK2001: unresolved external symbol "public: static long * Line::xc2" (?xc2@Line@@2PAJA)
1>main.obj : error LNK2001: unresolved external symbol "public: static long * Line::yc1" (?yc1@Line@@2PAJA)
1>main.obj : error LNK2001: unresolved external symbol "public: static long * Line::xc1" (?xc1@Line@@2PAJA)
1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>D:\Visual C++ Projects\Capture_Mouse_Line\Debug\Capture_Mouse_Line.exe : fatal error LNK1120: 5 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here is my code:

#include<allegro5\allegro.h>
#include<allegro5\allegro_native_dialog.h>
#include<allegro5\allegro_primitives.h>
#include<Windows.h>
#include<allegro5\allegro_windows.h>

#ifndef WIDTH
#define WIDTH 1440
#endif

#ifndef HEIGHT 
#define HEIGHT 900
#endif

class Line
{
public:
    static void ErasePreviousLine();

    static void DrawLine(long* x, long* y,long* x2,long* y2);

    static bool Erasable();


static long* xc1;
static long* yc1;
static long* xc2;
static long* yc2;
};

 void Line::ErasePreviousLine()
{

    delete xc1;
    xc1 = NULL;
    delete yc1;
    yc1 = NULL;
    delete xc2;
    xc2 = NULL;
    delete yc2;
    yc2 = NULL;
 }

 bool Line::Erasable()
 {
     if(xc1 && yc1 && xc2 && yc2 == NULL)
     {
         return false;
     }
     else
     {
         return true;
     }
 }

 void Line::DrawLine(long* x,long* y,long* x2,long* y2)
 {

     if(!al_init_primitives_addon())
     {
         al_show_native_message_box(NULL,NULL,NULL,"failed to initialize allegro",
        NULL,NULL);
     }

     xc1 = x;
     yc1 = y;
     xc2 = x2;
     yc2 = y2;

     al_draw_line((float)*xc1, (float)*yc1, (float)*xc2, (float)*yc2,al_map_rgb(255,0,255), 1);

     delete x;
     delete y;
     delete x2;
     delete y2;
 }


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

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;


    ALLEGRO_DISPLAY* display = NULL;

    if(!al_init())
    {
        al_show_native_message_box(NULL,NULL,NULL,"failed to initialize allegro",
        NULL,NULL);

        return -1;
    }

    display = al_create_display(WIDTH,HEIGHT);

    if(!display)
    {
        al_show_native_message_box(NULL,NULL,NULL,"failed to initialize display",
        NULL,NULL);

        return -1;
    }

    HWND hwnd = al_get_win_window_handle(display);


    if(hwnd == NULL)
    {
        MessageBox(NULL, "Window Creation Failed!", "Error!",
            MB_ICONEXCLAMATION | MB_OK);
        return 0;
    }


    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);


    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static bool bIsCaptured;
    static POINTS ptsBegin;
    static POINTS ptsEnd;
    switch(msg)
    {
    case WM_LBUTTONDOWN:
        SetCapture(hwnd);
        bIsCaptured = true;
        ptsBegin = MAKEPOINTS(lParam);
        return 0;
    case WM_MOUSEMOVE:
        if(wParam & MK_LBUTTON)
        {
            if(!Line::Erasable())
            {
                return 0;
            }

            Line::ErasePreviousLine();

            ptsEnd = MAKEPOINTS(lParam);

            Line::DrawLine(new long(ptsBegin.x),new long(ptsBegin.y),new long(ptsEnd.x),new long(ptsEnd.y));
        }
        break;

    case WM_LBUTTONUP:
        bIsCaptured = false;
        ReleaseCapture();
        break;

    case WM_ACTIVATEAPP:
        {
            if(wParam == TRUE)
            {
                if(bIsCaptured){
                    SetCapture(hwnd);}
            }
        }
        break;
    }
    return 0;
}

© Game Development or respective owner

Related posts about c++

Related posts about geometry