Unresolved External Symbol Error

Started by
8 comments, last by SDan 15 years, 10 months ago
I'm trying out the tutorial here, http://www.directxtutorial.com/Tutorial9/B-Direct3DBasics/dx9B1.aspx#still The code is as almost exactly as its put on that site. The only difference is that I took off the L's before the strings. however when I go to build, it comes up with this error error LNK2019: unresolved external symbol _Direct3DCreate9@4 referenced in function "void __cdecl initD3D(struct HWND__ *)" (?initD3D@@YAXPAUHWND__@@@Z) I have DirectX and all the file's (should) be in place so I'm not sure why that error is appearing. I can see that function and all when I check the directX files too. Anyone know why it's happening?
Advertisement
post the code (with [ source ][ / source ])
You're not linking against d3d.
There are two ways this can be done.
1. Menu at the top of VS 2005, VS 2008
Project->Properties->Configuration Properties->Linker->Input

Once you are done you should see something on the right hand side marked
Additional Dependencies. This is were you would put d3d9.lib and d3dx9.lib, or any other library that your program needs.

2.
#include <d3d9.h>
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")
** boolean010 **
lol, cheesy to request rating.
I thought I put a little bit too much in my post. I'll fix it. :)
** boolean010 **
Nope, it's still not working after I put the additional dependencies.
Here's the slightly modified code from the tutorial I posted above.

// include the basic windows header files and the Direct3D header file#include <windows.h>#include <windowsx.h>#include <d3d9.h>// include the Direct3D Library file#pragma comment (lib, "d3d9.lib")#pragma comment(lib, "d3dx9.lib")// global declarationsLPDIRECT3D9 d3d;    // the pointer to our Direct3D interfaceLPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class// function prototypesvoid initD3D(HWND hWnd);    // sets up and initializes Direct3Dvoid render_frame(void);    // renders a single framevoid cleanD3D(void);    // closes Direct3D and releases memory// the WindowProc function prototypeLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);// the entry point for any Windows programint WINAPI WinMain(HINSTANCE hInstance,                   HINSTANCE hPrevInstance,                   LPSTR lpCmdLine,                   int nCmdShow){    HWND hWnd;    WNDCLASSEX wc;    ZeroMemory(&wc, sizeof(WNDCLASSEX));    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 = "WindowClass";    RegisterClassEx(&wc);    hWnd = CreateWindowEx(NULL,                          "WindowClass",                          "Our First Direct3D Program",                          WS_OVERLAPPEDWINDOW,                          300, 300,                          640, 480,                          NULL,                          NULL,                          hInstance,                          NULL);    ShowWindow(hWnd, nCmdShow);    // set up and initialize Direct3D    initD3D(hWnd);    // enter the main loop:    MSG msg;    while(TRUE)    {        DWORD starting_point = GetTickCount();        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))        {            if (msg.message == WM_QUIT)                break;            TranslateMessage(&msg);            DispatchMessage(&msg);        }        render_frame();        while ((GetTickCount() - starting_point) < 25);    }    // clean up DirectX and COM    cleanD3D();    return msg.wParam;}// this is the main message handler for the programLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    switch(message)    {        case WM_DESTROY:            {                PostQuitMessage(0);                return 0;            } break;    }    return DefWindowProc (hWnd, message, wParam, lParam);}// this function initializes and prepares Direct3D for usevoid initD3D(HWND hWnd){    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D    // create a device class using this information and the info from the d3dpp stuct    d3d->CreateDevice(D3DADAPTER_DEFAULT,                      D3DDEVTYPE_HAL,                      hWnd,                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,                      &d3dpp,                      &d3ddev);    return;}// this is the function used to render a single framevoid render_frame(void){    // clear the window to a deep blue    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);    d3ddev->BeginScene();    // begins the 3D scene    // do 3D rendering on the back buffer here    d3ddev->EndScene();    // ends the 3D scene    d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen    return;}// this is the function that cleans up Direct3D and COMvoid cleanD3D(void){    d3ddev->Release();    // close and release the 3D device    d3d->Release();    // close and release Direct3D    return;}


I'm using the june 2008 directX sdk if that makes a difference.
And the error is still the same.
i had the same problem. i just made a few changes, following hte sample provided with the dx browser. worked just fine...

this is my code:(header and source)

main.h
========
#ifndef _main_h#define _main_h#include <windows.h>#include <windowsx.h>#include <d3d9.h>#include <d3dx9.h>// include the Direct3D Library file#pragma comment(lib,"d3d9.lib")#pragma comment(lib,"d3dx9.lib")//-----------------------------------------------------------------------------// Global variables//-----------------------------------------------------------------------------LPDIRECT3D9             g_pD3D       = NULL; // Used to create the D3DDeviceLPDIRECT3DDEVICE9       g_pd3dDevice = NULL; // Our rendering device// function prototypesHRESULT InitD3D( HWND hWnd );    // sets up and initializes Direct3DVOID Render();    // renders a single frameVOID Cleanup();		// closes Direct3D and releases memoryconst int FPS		    =   60;const int SCREEN_WIDTH	=	1024;const int SCREEN_HEIGHT	=	768;const int WINDOW_WIDTH	=	640;const int WINDOW_HEIGHT	=	480;#endif


main.cpp
=========
#include "main.h"// the WindowProc function prototypeLRESULT CALLBACK WindowProc(HWND hWnd,							UINT message,							WPARAM wParam,							LPARAM lParam);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));		// set the window class properties	wc.cbSize			= sizeof(WNDCLASSEX);	wc.style			= CS_HREDRAW | CS_VREDRAW;	wc.lpfnWndProc		= (WNDPROC)WindowProc;	wc.hInstance		= hInstance;	wc.hCursor			= LoadCursor(NULL, IDC_HAND);	wc.hbrBackground	= (HBRUSH)COLOR_MENUBAR;	wc.lpszClassName	= L"WINDOWS_CLASS_1";	// register the window class	RegisterClassEx(&wc);	// create window and use it as the handle	hWnd = CreateWindowEx(WS_EX_CLIENTEDGE,							L"WINDOWS_CLASS_1",							L"GAME WINDOW",							WS_OVERLAPPED,							SCREEN_WIDTH/2 - WINDOW_WIDTH/2,							SCREEN_HEIGHT/2 - WINDOW_HEIGHT/2,							WINDOW_WIDTH,							WINDOW_HEIGHT,							NULL,							NULL,							hInstance,							NULL);	// display window on the screen	ShowWindow(hWnd, nCmdShow);	// set up and initialize Direct3D    InitD3D(hWnd);		// this struct holds Windows event messages	MSG msg;		// Enter the infinite message loop	while(true)	{		// find out the starting time of each loop        DWORD starting_point = GetTickCount();		// Check to see if any messages are waiting in the queue		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))		{			// If the message is WM_QUIT, exit the while loop			if (msg.message == WM_QUIT || msg.wParam == VK_ESCAPE)				break;			// translate keystroke messages into the right format			TranslateMessage(&msg);			// send the message to the WindowProc function			DispatchMessage(&msg);		}		//Game Code Here...		Render();		// wait until 1/40th of a second has passed        while ((GetTickCount() - starting_point) < 1/FPS);	}		// clean up DirectX and COM    Cleanup();	return msg.wParam;}// this is the main message handler for the programLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){	// sort through and find what code to run for the message given	switch(message)	{		case WM_DESTROY:			{				//close application entirely				PostQuitMessage(0);				return 0;			}			break;	}	 // Handle any messages the switch statement didn't    return DefWindowProc (hWnd, message, wParam, lParam);}//-----------------------------------------------------------------------------// Name: InitD3D()// Desc: Initializes Direct3D//-----------------------------------------------------------------------------HRESULT InitD3D( HWND hWnd ){    // Create the D3D object, which is needed to create the D3DDevice.    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )        return E_FAIL;    // Set up the structure used to create the D3DDevice. Most parameters are    // zeroed out. We set Windowed to TRUE, since we want to do D3D in a    // window, and then set the SwapEffect to "discard", which is the most    // efficient method of presenting the back buffer to the display.  And     // we request a back buffer format that matches the current desktop display     // format.    D3DPRESENT_PARAMETERS d3dpp;     ZeroMemory( &d3dpp, sizeof(d3dpp) );    d3dpp.Windowed = TRUE;    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;    // Create the Direct3D device. Here we are using the default adapter (most    // systems only have one, unless they have multiple graphics hardware cards    // installed) and requesting the HAL (which is saying we want the hardware    // device rather than a software one). Software vertex processing is     // specified since we know it will work on all cards. On cards that support     // hardware vertex processing, though, we would see a big performance gain     // by specifying hardware vertex processing.    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,                                      &d3dpp, &g_pd3dDevice ) ) )    {        return E_FAIL;    }    // Device state would normally be set here    return S_OK;}//-----------------------------------------------------------------------------// Name: Cleanup()// Desc: Releases all previously initialized objects//-----------------------------------------------------------------------------VOID Cleanup(){    if( g_pd3dDevice != NULL)         g_pd3dDevice->Release();    if( g_pD3D != NULL)        g_pD3D->Release();}//-----------------------------------------------------------------------------// Name: Render()// Desc: Draws the scene//-----------------------------------------------------------------------------VOID Render(){    if( NULL == g_pd3dDevice )        return;    // Clear the backbuffer to a blue color    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );        // Begin the scene    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )    {        // Rendering of scene objects can happen here            // End the scene        g_pd3dDevice->EndScene();    }    // Present the backbuffer contents to the display    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );}


Hope that helps. Its about time i started contributing to this forum for all it has helped me!!

[Edited by - abhelande on June 24, 2008 12:16:51 AM]
you should use source tags next time you post code abhelande. It makes everything much easier to read and understand.

[ source ]

code

[ /source ]


With out the spaces of course.
I managed to fix the problem, thanks for the help guys.

This topic is closed to new replies.

Advertisement