Archived

This topic is now archived and is closed to further replies.

Linker Error

This topic is 5819 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm just beginning to learn DirectX for windows, and keep getting a problem with the linker with all of my own functions. Here's the error: --------------------Configuration: Mine - Win32 Debug------------ Linking... Main_Shell.obj : error LNK2001: unresolved external symbol "int __cdecl Game_Shutdown(void)" (?Game_Shutdown@@YAHXZ) Main_Shell.obj : error LNK2001: unresolved external symbol "int __cdecl Game_Main(void)" (?Game_Main@@YAHXZ) Main_Shell.obj : error LNK2001: unresolved external symbol "int __cdecl Game_Init(void)" (?Game_Init@@YAHXZ) Debug/Mine.exe : fatal error LNK1120: 3 unresolved externals Error executing link.exe. Mine.exe - 4 error(s), 0 warning(s) The other functions work fine. Any help would be greatly appreciated. Giant One Edited by - GiantOne on January 11, 2002 9:54:59 AM

Share this post


Link to post
Share on other sites
Well, here''s the entire source, anyway. *shrug* I have no clue what''s wrong.....

// INCLUDES ///////////////////////////////////////////
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>
#include "ddraw.h"


int Game_Init(void);
int Game_Shutdown(void);
int Game_Main(void);


// DEFINES ///////////////////////////////////////////
// defines for windows
#define WINDOW_CLASS_NAME "WINCLASS1"

// GLOBALS ///////////////////////////////////////////
HWND main_window = NULL; // save the window handle
LPDIRECTDRAW lpdd; // pointer to interface object

// FUNCTIONS ////////////////////////////////////////

// *********************
// * EVENT HANDLER *
// *********************

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg,
WPARAM wparam, LPARAM lparam)
{
// this is the main message handler of the system
PAINTSTRUCT ps; // used in WM_PAINT
HDC hdc; //handle to a device context

//find out what the message is
switch(msg)
{
case WM_CREATE: // called when window is created
{
// ** DO INITIALIZATION STUFF HERE **
return(0);
} break;

case WM_PAINT: // called when window needs painting
{
// simply validate the window
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return(0);
} break;

case WM_COMMAND: // called when menu item is selected
{
//what menu item?
switch(wparam)
{
case 1000:
{ } break;

case 1001:
{ } break;

case 1002:
{ } break;

case 2000:
{ } break;

default: break;

} // end switch
} break;


case WM_DESTROY: // called when window is killed
{
//kill the application
PostQuitMessage(0);
return(0);
} break;

default: break;
} // end switch

//process any messages that you didn''t take care of
return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc

// WINMAIN ///////////////////////////////////
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance,
LPSTR lpcmdline, int ncmdshow)
{
WNDCLASS winclass; // this will hold the class you create
HWND hwnd; // generic window handle
MSG msg; // generic message

// first, fill in the window class structure
winclass.style = CS_DBLCLKS | CS_OWNDC | // give window its own device context and
CS_HREDRAW | CS_VREDRAW; // send a message on: double clicks, resize

winclass.lpfnWndProc = WindowProc; // pointer to event handler

winclass.cbClsExtra = 0; // extra bytes

winclass.cbWndExtra = 0; // extra bytes

winclass.hInstance = hinstance; // handle of instance

winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // handle to icon

winclass.hCursor = LoadCursor(NULL, IDC_ARROW); // handle to cursor

winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // handle to background brush

winclass.lpszMenuName = "MyMenu"; // name of menu

winclass.lpszClassName = WINDOW_CLASS_NAME; // name of class

// register the window class
if (!RegisterClass(&winclass))
return(0);
// create the window
if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, //class
"Hello", //title
WS_OVERLAPPEDWINDOW | WS_VISIBLE, //flags
0, 0, // x,y
320, 200, // width, height
NULL, // handle to parent
NULL, // handle to menu
hinstance, //instance
NULL))) // creation parameters
return(0);

//save the window handle in a global
main_window = hwnd;

// perform all game-console-specific initialization
Game_Init();


//enter main event loop
while(1)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) // checks for message and processes it
{
// test whether this is a quit
if (msg.message == WM_QUIT) break;

// translate accelerator keys
TranslateMessage(&msg);

//send the message to the window proc
DispatchMessage(&msg);
} // end if

// ************************************
// ** MAIN GAME PROCESSING GOES HERE **
// ************************************
Game_Main();

} // end while

// shut down the game and release all resources
Game_Shutdown();

//return to windows like this
return(msg.wParam);
} // end WinMain


int Game_Init(void *parms)
{
// do all initialization for your game in this function

// *************************
// ** YOUR CODE GOES HERE **
// *************************

// create object and test for error
if (DirectDrawCreate(NULL, &lpdd, NULL) != DD_OK)
return(0);

// set cooperation level to windowed mode normal
lpdd -> SetCooperativeLevel(main_window, DDSCL_NORMAL);

//return success
return(1);

} // end Game_Init


////////////////////////////////////////////////////////////

int Game_Shutdown(void *parms)
{
// shut down your game and release all resources that you
// allocated in this function

// ***************************
// ** YOUR CODE GOES HERE **
// ***************************

// release the DirectDraw object
if (lpdd != NULL)
lpdd -> Release();

// return success
return(1);

} // end Game_Shutdown

///////////////////////////////////////////////////////////

int Game_Main(void *parms)
{
// **************************************************************
// * This is the workhorse of your game: It will be called *
// * continuously in real-time, like main() in C; all the *
// * calls for your game go here! *
// **************************************************************

// *****************************
// ** YOUR CODE GOES HERE **
// *****************************

// return success
return(1);

} // end Game_Main




If it looks familiar --> I''m using LaMothe''s "Window''s Game Programming for Dummies". That''s where this is from.

Giant One

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Your three function forward declarations don''t match the prototypes for your implementations.

int Game_Init(void);
int Game_Shutdown(void);
int Game_Main(void);

int Game_Init(void *parms)
{
...
}

int Game_Shutdown(void *parms)
{
...
}

int Game_Main(void *parms)
{
...
}

The parameters gotta match, so either add *params to your prototypes, or remove it from your implementations.

Share this post


Link to post
Share on other sites