Archived

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

Dko

A complile prob

Recommended Posts

Ok ive been useing the tuts on andypike.com to learn DirectX and have much sucssess with them untill I got to the 3rd one when I comple it I get unresolved external symbol errors(the bane of my existance) >_< Well here they are and bellow them is my code. But I have the susspician that whats wrong is that he forgot to have us(the readers) put in a library into the project as I only have one DirectX lib and ive seen more in other tutorials.
quote:
--------------------Configuration: DX Project 1 - Win32 Debug-------------------- Compiling... Main.cpp c:\my documents\c++ programs\dx project 1\main.cpp(74) : warning C4305: ''initializing'' : truncation from ''unsigned long'' to ''float'' c:\my documents\c++ programs\dx project 1\main.cpp(81) : warning C4305: ''initializing'' : truncation from ''unsigned long'' to ''float'' c:\my documents\c++ programs\dx project 1\main.cpp(86) : warning C4305: ''initializing'' : truncation from ''unsigned long'' to ''float'' c:\my documents\c++ programs\dx project 1\main.cpp(91) : warning C4305: ''initializing'' : truncation from ''unsigned long'' to ''float'' c:\my documents\c++ programs\dx project 1\main.cpp(95) : warning C4305: ''initializing'' : truncation from ''unsigned long'' to ''float'' c:\my documents\c++ programs\dx project 1\main.cpp(99) : warning C4305: ''initializing'' : truncation from ''unsigned long'' to ''float'' Linking... Main.obj : error LNK2001: unresolved external symbol _D3DXMatrixMultiply@12 Main.obj : error LNK2001: unresolved external symbol _D3DXMatrixRotationZ@8 Main.obj : error LNK2001: unresolved external symbol _D3DXMatrixRotationY@8 Main.obj : error LNK2001: unresolved external symbol _D3DXMatrixRotationX@8 Main.obj : error LNK2001: unresolved external symbol __imp__timeGetTime@0 Main.obj : error LNK2001: unresolved external symbol _D3DXMatrixLookAtLH@16 Main.obj : error LNK2001: unresolved external symbol _D3DXMatrixPerspectiveFovLH@20 Debug/DX Project 1.exe : fatal error LNK1120: 7 unresolved externals Error executing link.exe. DX Project 1.exe - 8 error(s), 6 warning(s)
#include <d3dx8.h>

LPDIRECT3D8 g_pD3D = NULL;
LPDIRECT3DDEVICE8 g_pD3DDevice = NULL;
LPDIRECT3DVERTEXBUFFER8 g_pVertexBuffer = NULL; // Beffer to hold vertices


struct CUSTOMVERTEX
{
	FLOAT x, y, z, rhw; // The transformed position for the vertex.

	DWORD color; // The vertex color.

};

#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

#define SafeRelease(pObject) if (pObject != NULL) {pObject->Release(); pObject = NULL;}


HRESULT InitialiseD3D(HWND hWnd)
{
	//First of all, create the main D3D object. If it is created successfully we

	//should get a pointer to an IDirect3D8 interface.

	g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);
	if(g_pD3D == NULL)
	{
		return E_FAIL;
	}

	// Get the current display mode

	D3DDISPLAYMODE d3ddm;
	if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
	{
		return E_FAIL;
	}

	//Create a structure to hold the settings for our device

	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));

	//Fill the structure.

	//We want our program to be windowed, and set the back buffer to a format

	//that matches our current display mode

	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;
	d3dpp.BackBufferFormat = d3ddm.Format;

	//Create a Direct3D device

	if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
								   D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice)))
	{
		return E_FAIL;
	}

	// Turn on back face culling. This is because we want to hide the back of our polygons

	g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);

	// Turn off lighting becase we are specifying that our vertices hace color

	g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

	return S_OK;
}

HRESULT InitialiseVertexBuffer()
{
	void *pVertices;

	// Store each point of the cube together with it''s colour

	// Make sure that the points of a polygon are specified in a clockwise direction,

	// this is because anti-clockwise faces will be culled

	// We will use a three triangle strips to render these polygons (Top, Sides, Bottom).

	CUSTOMVERTEX cvVertices[] =
	{
		// Top Face

		{-5.0f, 5.0f, -5.0f, D3DCOLOR_XRGB(0, 0, 255),}, // Vertex 0 - Blue

		{-5.0f, 5.0f, 5.0f, D3DCOLOR_XRGB(255, 0, 0),}, // Vertex 1 - Red

		{5.0f, 5.0f, -5.0f, D3DCOLOR_XRGB(255, 0, 0),}, // Vertex 2 - Red

		{5.0f, 5.0f, 5.0f, D3DCOLOR_XRGB(0, 255, 0),}, // Vertex 3 - Green


		// Face 1

		{-5.0f, -5.0f, -5.0f, D3DCOLOR_XRGB(255, 0, 0),}, // Vertex 4 - Red

		{-5.0f, 5.0f, -5.0f, D3DCOLOR_XRGB(0, 0, 255),}, // Vertex 5 - Blue

		{5.0f, -5.0f, -5.0f, D3DCOLOR_XRGB(0, 255, 0),}, // Vertex 6 - Green

		{5.0f, 5.0f, -5.0f, D3DCOLOR_XRGB(255, 0, 0),}, // Vertex 7 - Red


		// Face 2

		{5.0f, -5.0f, 5.0f, D3DCOLOR_XRGB(0, 0, 255),}, // Vertex 8 - Blue

		{5.0f, 5.0f, 5.0f, D3DCOLOR_XRGB(0, 255, 0),}, // Vertex 9 - Green


		// Face 3

		{-5.0f, -5.0f, -5.0f, D3DCOLOR_XRGB(255, 0, 0),}, // Vertex 10 - Green

		{-5.0f, 5.0f, -5.0f, D3DCOLOR_XRGB(0, 0, 255),}, // Vertex 11 - Red


		// Face 4

		{-5.0f, -5.0f, -5.0f, D3DCOLOR_XRGB(255, 0, 0),}, // Vertex 12 - Red

		{-5.0f, 5.0f, -5.0f, D3DCOLOR_XRGB(0, 0, 255),}, // Vertex 13 - Blue


		// Bottom Face

		{5.0f, -5.0f, -5.0f, D3DCOLOR_XRGB(0, 255, 0),}, // Vertex 14 - Green

		{5.0f, -5.0f, 5.0f, D3DCOLOR_XRGB(0, 0, 255),}, // Vertex 15 - Blue

		{-5.0f, -5.0f, -5.0f, D3DCOLOR_XRGB(255, 0, 0),}, // Vertex 16 - Red

		{-5.0f, -5.0f, 5.0f, D3DCOLOR_XRGB(0, 255, 0),}, // Vertex 17 - Green

	};

	//Create the vertex buffer from our device

	if(FAILED(g_pD3DDevice->CreateVertexBuffer(18 * sizeof(CUSTOMVERTEX),
											   0, D3DFVF_CUSTOMVERTEX,
											   D3DPOOL_DEFAULT, &g_pVertexBuffer)))
	{
		return E_FAIL;
	}

	//Get a pointer to the vertex buffer vertices and lock the vertex buffer

	if(FAILED(g_pVertexBuffer->Lock(0, sizeof(cvVertices), (BYTE**)&pVertices, 0)))
	{
		return E_FAIL;
	}

	//Copy our stored vertices values into the vertex buffer

	memcpy(pVertices, cvVertices, sizeof(cvVertices));

	//Unlock the vertex buffer

	g_pVertexBuffer->Unlock();
	
	return S_OK;
}

void SetupRotation()
{
	// Here we will rotate our world around the x, y and z axis.

	D3DXMATRIX matWorld, matWorldX, matWorldY, matWorldZ;

	// Create the transformation matrices

	D3DXMatrixRotationX(&matWorldX, timeGetTime()/400.0f);
	D3DXMatrixRotationY(&matWorldY, timeGetTime()/400.0f);
	D3DXMatrixRotationZ(&matWorldZ, timeGetTime()/400.0f);

	// Combine the transformations by multiplying them together

	D3DXMatrixMultiply(&matWorld, &matWorldX, &matWorldY);
	D3DXMatrixMultiply(&matWorld, &matWorld, &matWorldZ);

	// Apply the transformation

	g_pD3DDevice->SetTransform(D3DTS_WORLD, &matWorld);
}

void SetupCamera()
{
	// Here we will setup the camera.

	// The camera has three settings: "Camera Position", "Look at Position" and "Up Direction"

	// We have set the following:

	// Camera Position: (0, 0, -30)

	// Look at Position: (0, 0, 0)

	// Up direction: Y-Axis.

	D3DXMATRIX matView;
	D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(0.0f, 0.0f, -30.0f), // Camera Position

								 &D3DXVECTOR3(0.0f, 0.0f, 0.0f), // Look at Position

								 &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); // Up Direction

	g_pD3DDevice->SetTransform(D3DTS_VIEW, &matView);
}

void SetupPerspective()
{
	// Here we specify the field of view, aspect ration and near and far clipping planes.

	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 500.0f);
	g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &matProj);
}

void Render()
{
	if(g_pD3DDevice == NULL)
	{
		return;
	}
	
	// Clear the backbuffer to black

	g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	// Begin the scene

	g_pD3DDevice->BeginScene();

	// Setup the rotation, camera, and perspective matrices

	SetupRotation();
	SetupCamera();
	SetupPerspective();

	// Rendering our objects

	g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer, sizeof(CUSTOMVERTEX));
	g_pD3DDevice->SetVertexShader(D3DFVF_CUSTOMVERTEX);
	g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2); // Top

	g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 4, 8); // Sides

	g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 14, 2); // Bottom


	// End the scene

	g_pD3DDevice->EndScene();

	// Flip the back and front buffers so that whatever had been rendered on the back buffer

	// will now be visible on screen (front buffer).

	g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}

void CleanUp()
{
	SafeRelease(g_pVertexBuffer);
	SafeRelease(g_pD3DDevice);
	SafeRelease(g_pD3D);
}

void GameLoop()
{
	//Enter the game loop

	MSG msg;
	BOOL fMessage;

	PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);

	while(msg.message != WM_QUIT)
	{
		fMessage = PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);

		if(fMessage)
		{
			//Process message

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// No message to process, so render the current scene

			Render();
		}
	}
}

//The windows message handler

LRESULT WINAPI WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
		break;
		case WM_KEYUP:
			switch(wParam)
			{
			case VK_ESCAPE:
				// User has pressed the escape key, so quit

				DestroyWindow(hWnd);
				return 0;
			break;
			}
		break;
	}
	return DefWindowProc(hWnd, msg, wParam, lParam);
}

// Application entry point

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
{
	//Register the window class

	WNDCLASSEX wc = {sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0, 0,
					 GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
					 "DX Project 3", NULL};
	RegisterClassEx(&wc);

	//Create the application''s window

	HWND hWnd = CreateWindow("DX Project 3", "www.andypike.com: Tutorial 3",
							   WS_OVERLAPPEDWINDOW, 50, 50, 500, 500,
							   GetDesktopWindow(), NULL, wc.hInstance, NULL);

	// Initialize Direct3D

	if(SUCCEEDED(InitialiseD3D(hWnd)))
	{
		// Show our window

		ShowWindow(hWnd, SW_SHOWDEFAULT);
		UpdateWindow(hWnd);
		
		// Initialze Vertex Buffer

		if(SUCCEEDED(InitialiseVertexBuffer()))
		{

			// Start game running: Enter the game loop

			GameLoop();
		}
	}

	CleanUp();

	UnregisterClass("DX Project 3", wc.hInstance);

	return 0;
}

Share this post


Link to post
Share on other sites
Thanks, when I saw the d3dx8.lib I knew that was the bugger I needed, because this tut uses d3dx8 quite a bit

Though Im still getting this

quote:

Linking...
Main.obj : error LNK2001: unresolved external symbol __imp__timeGetTime@0
Debug/DX Project 1.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.



[edited by - Dko on October 22, 2003 8:18:29 PM]

Share this post


Link to post
Share on other sites
Shesh this is just not my day! >_< I included winmm.lib (Instead of what you said because that wouldn't work and used good old google to find out why Now the program runs but the 3d box does not appear O_o Just blackness.

Edit: Nm I figured it out, there where little differances with his program to mine like I changed his INT to int (me thinking it was a type ) and not changeing FLOAT x, y, z, awr; to just FLOAT x, y, z;

Thanks everyone for your help I now have a happy multi colored cube rotating on my computer ^_^

[edited by - Dko on October 22, 2003 8:53:21 PM]

Share this post


Link to post
Share on other sites