CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2009
    Posts
    24

    unresolved external errors

    This problem has stumped me all afternoon. I have 2 function in the gameInititalize header, they are defined in Engine.cpp, and called in Entry.cpp. I had same problems with some DirectX function calls, but they when away when I did pragma for 2 directX libraries. Help is appreciated.

    errors

    Code:
    error LNK2019: unresolved external symbol "void __cdecl gameEnd(void)" (?gameEnd@@YAXXZ) referenced in function _WinMain@16
     error LNK2019: unresolved external symbol "void __cdecl gameRun(struct HWND__ *)" (?gameRun@@YAXPAUHWND__@@@Z) referenced in function _WinMain@16
    gameInitialize.h
    Code:
    #include <d3d9.h>
    #include <d3dx9.h>
    #include <windows.h>
    #include <string>
    using namespace std;
    
    
    #pragma comment(lib,"d3d9.lib")
    #pragma comment(lib,"d3dx9.lib")
    
    extern LPDIRECT3DDEVICE9 d3ddev; 
    extern LPDIRECT3D9 d3d; 
    extern LPDIRECT3DSURFACE9 backbuffer;
    
    extern LPDIRECT3DTEXTURE9 Left_L;
    extern LPDIRECT3DTEXTURE9 Left_Z;
    extern LPDIRECT3DTEXTURE9 Right_L;
    extern LPDIRECT3DTEXTURE9 Right_Z;
    extern LPDIRECT3DTEXTURE9 Square;
    extern LPDIRECT3DTEXTURE9 T_Shape;
    extern LPDIRECT3DTEXTURE9 VerticalShape;
    
    void gamenInit(HWND window);
    void gameRun(HWND window);
    void gameEnd();
    
    void loadTextures();
    LPDIRECT3DTEXTURE9 loadFile(string name);
    Engine.cpp
    Code:
    #include "Collision.h"
    #include "Shape.h"
    #include "shapeConstructor.h"
    #include "userInterfaces.h"
    #include "gameInitialize.h"
    
    int SCREENW = 1024;
    int SCREENH = 768;
    
    LPDIRECT3DDEVICE9 d3ddev = NULL; 
    LPDIRECT3D9 d3d = NULL; 
    LPDIRECT3DSURFACE9 backbuffer = NULL;
    
    LPDIRECT3DTEXTURE9 Left_L  = NULL;
    LPDIRECT3DTEXTURE9 Left_Z  = NULL;
    LPDIRECT3DTEXTURE9 Right_L = NULL;
    LPDIRECT3DTEXTURE9 Right_Z = NULL;
    LPDIRECT3DTEXTURE9 Square = NULL;
    LPDIRECT3DTEXTURE9 T_Shape = NULL;
    LPDIRECT3DTEXTURE9 VerticalShape = NULL;
    
    void gamenInit(HWND window)
    {
    	d3d = Direct3DCreate9(D3D_SDK_VERSION);
        
        //set Direct3D presentation parameters
        D3DPRESENT_PARAMETERS d3dpp; 
        ZeroMemory(&d3dpp, sizeof(d3dpp));
        d3dpp.Windowed = true;
        d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
        d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
        d3dpp.BackBufferCount = 1;
        d3dpp.BackBufferWidth = SCREENW;
        d3dpp.BackBufferHeight = SCREENH;
        d3dpp.hDeviceWindow = window;
    
        //create Direct3D device
        d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
            D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev);
    
        //get a pointer to the back buffer surface
        d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);
    }
    
    void loadTextures()
    {
                    
    	 Left_L = loadFile("Left_L");
    	 Left_Z = loadFile("Left_Z");
    	 Right_L = loadFile("Right_L");
    	 Right_Z = loadFile("Right_Z");
    	 Square = loadFile("Square");
    	 T_Shape = loadFile("T_Shape");
    	 VerticalShape = loadFile("VerticalShape");
    }
    
    LPDIRECT3DTEXTURE9 loadFile(string name)
    {
    	D3DXIMAGE_INFO info;
    	LPDIRECT3DTEXTURE9 texture = NULL;
    	D3DCOLOR transcolor = D3DCOLOR_XRGB(0,0,0);
    	HRESULT result = D3DXGetImageInfoFromFile(name.c_str(), &info);
    
    	D3DXCreateTextureFromFileEx( 
            d3ddev,                //Direct3D device object
            name.c_str(),      //bitmap filename
            info.Width,            //bitmap image width
            info.Height,           //bitmap image height
            1,                     //mip-map levels (1 for no chain)
            D3DPOOL_DEFAULT,       //the type of surface (standard)
            D3DFMT_UNKNOWN,        //surface format (default)
            D3DPOOL_DEFAULT,       //memory class for the texture
            D3DX_DEFAULT,          //image filter
            D3DX_DEFAULT,          //mip filter
            transcolor,            //color key for transparency
            &info,                 //bitmap file info (from loaded file)
            NULL,                  //color palette
            &texture );
    
    	return texture;
    }
    Entry.cpp
    Code:
    #include <windows.h>
    #include "gameInitialize.h"
    
    bool gameover = false;
    using namespace std;
    
    LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
    {
        switch( msg )
        {
            case WM_DESTROY:
    			gameover = true;
                PostQuitMessage(0);
                return 0;
        }
        return DefWindowProc( hWnd, msg, wParam, lParam );
    }
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
        //initialize window settings
        WNDCLASSEX wc;
        wc.cbSize = sizeof(WNDCLASSEX); 
        wc.style         = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc   = (WNDPROC)WinProc;
        wc.cbClsExtra	 = 0;
        wc.cbWndExtra	 = 0;
        wc.hInstance     = hInstance;
        wc.hIcon         = NULL;
        wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        wc.lpszMenuName  = NULL;
        wc.lpszClassName = "Tetris";
        wc.hIconSm       = NULL;
        RegisterClassEx(&wc);
    
        //create a new window
        HWND window = CreateWindow( "Tetris", "Tetris",
           WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
           1024, 768, NULL, NULL, hInstance, NULL);
        if (window == 0) return 0;
    
        //display the window
        ShowWindow(window, nCmdShow);
        UpdateWindow(window);
    	
    	//initialize the game
        gamenInit(window);
    
        // main message loop
    	MSG message;
    	while (!gameover)
        {
            if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) 
    	    {
    		    TranslateMessage(&message);
    		    DispatchMessage(&message);
    	    }
    
            //process game loop 
            gameRun(window);
        }
    
        //shutdown
        gameEnd();
    	return message.wParam;
    }

  2. #2
    Join Date
    Jul 2009
    Posts
    24

    Re: unresolved external errors

    I managed to fix it. I didnt define functions gameRun() and gameEnd() in the Engine cpp file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured