Linked error(s)

Started by
7 comments, last by TransistoR 17 years, 10 months ago
I'm using Bloodshed Dev C++ compiler and when compiling a simple non-drawing DirectX window I get these errors: [Linker error] undefined reference to `D3DXMatrixPerspectiveFovLH@20' [Linker error] undefined reference to `Direct3DCreate9@4' Compile log looks like this: Compiler: Default compiler Executing g++.exe... g++.exe "C:\Documents and Settings\Administratorius\Desktop\Simple Basecode\main.cpp" -o "C:\Documents and Settings\Administratorius\Desktop\Simple Basecode\main.exe" -I"D:\Dev-Cpp\include\c++\3.3.1" -I"D:\Dev-Cpp\include\c++\3.3.1\mingw32" -I"D:\Dev-Cpp\include\c++\3.3.1\backward" -I"D:\Dev-Cpp\lib\gcc-lib\mingw32\3.3.1\include" -I"D:\Dev-Cpp\include" -L"D:\Dev-Cpp\lib" C:\DOCUME~1\ADMINI~2\LOCALS~1\Temp/ccUhcaaa.o(.text+0x4c):main.cpp: undefined reference to `D3DXMatrixPerspectiveFovLH@20' C:\DOCUME~1\ADMINI~2\LOCALS~1\Temp/ccUhcaaa.o(.text+0x72c):main.cpp: undefined reference to `Direct3DCreate9@4' Execution terminated Any suggestions why and how to fix these problems?
Advertisement
You forgot to include the DirectX libraries
-----BEGIN GEEK CODE BLOCK-----Version: 3.12GCS/M/S d->+(++) s+: a19? C++++ UL++ P+++ L+ !E W+++ N+ o++ K? w!O M-- V? !PS PE Y+ PGP t++ 5+++ X R tv+> b+(++)>+++ DI+++>+++++ D++G e>++++ h! r y?------END GEEK CODE BLOCK------
Did not.
Here is the source:
#include <windows.h>#include <d3dx9.h>#include <d3d9.h>#include "main.h"#pragma comment(lib, "D3d9.lib")#pragma comment(lib, "D3dx9.lib")HDC						hDC				= NULL;		    // Private GDI Device ContextHWND					hWnd			= NULL;		    // Holds Our Window HandleHINSTANCE				hInstance;					    // Holds The Instance Of The ApplicationLPDIRECT3D9				pD3D			= NULL;		    // DirectX 3D Version 9LPDIRECT3DDEVICE9		pD3DDevice		= NULL;		    // DirectX 3D Rendering Devicebool	keys[256];			                            // Array Used For The Keyboard Routinebool	active=TRUE;		                            // Window Active Flag Set To TRUE By Defaultbool	fullscreen=TRUE;	                            // Fullscreen Flag Set To Fullscreen Mode By DefaultLRESULT	CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);	// Declaration For WndProcvoid ReSizeD3DScene(int width, int height)				// Resize And Initialize The D3D Window{	if (height==0)										// Prevent A Divide By Zero By	{		height=1;										// Making Height Equal One	}	D3DXMATRIXA16 matProjection;						// Create A Projection Matrix	// Calculate The Aspect Ratio Of The Window	D3DXMatrixPerspectiveFovLH(&matProjection, 45.0f, (float)width/(float)height, 0.1f, 100.0f );	pD3DDevice->SetTransform( D3DTS_PROJECTION, &matProjection );	D3DXMatrixIdentity(&matProjection);					// Reset The Projection Matrix}int InitD3D()										   // All Setup For D3D Goes Here{	pD3DDevice->SetRenderState(D3DRS_ZENABLE,  TRUE ); // Enable Z-Buffer (Depth Buffer)    pD3DDevice->SetRenderState(D3DRS_CULLMODE, FALSE); // Disable Backface Culling    pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); // Disable Light	return TRUE;									   // Initialization Went OK}int DrawD3DScene()									    // Here's Where We Do All The Drawing{    pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, // Clear Screen And Depth Buffer								D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,0.0f), 1.0f, 0 );	pD3DDevice->BeginScene();	// Nothing To draw!!!	pD3DDevice->EndScene();	pD3DDevice->Present( NULL, NULL, NULL, NULL );		// Display Result	return TRUE;										// Keep Going}void KillD3DWindow()									// Properly Kill The Window{    if (pD3DDevice != NULL)	pD3DDevice->Release();		// Release D3D Device	if (pD3D != NULL) pD3D->Release();					// Release D3D Interface	if (fullscreen)										// Are We In Fullscreen Mode?	{		ChangeDisplaySettings(NULL,0);					// If So Switch Back To The Desktop		ShowCursor(TRUE);								// Show Mouse Pointer	}	if (hDC && !ReleaseDC(hWnd,hDC))					// Are We Able To Release The DC	{		MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);		hDC=NULL;										// Set DC To NULL	}	if (hWnd && !DestroyWindow(hWnd))					// Are We Able To Destroy The Window?	{		MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);		hWnd=NULL;										// Set hWnd To NULL	}	if (!UnregisterClass("Direct3D",hInstance))			// Are We Able To Unregister Class	{		MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);		hInstance=NULL;									// Set hInstance To NULL	}}/*	This Code Creates Our DirectX 3D Window.  Parameters Are:				* *	title			- Title To Appear At The Top Of The Window				* *	width			- Width Of The D3D Window Or Fullscreen Mode			* *	height			- Height Of The D3D Window Or Fullscreen Mode			* *	fullscreenflag	- Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE)	*/BOOL CreateD3DWindow(char* title, int width, int height, bool fullscreenflag){	WNDCLASS	wc;	DWORD		dwExstyle;				// Window Extended style	DWORD		dwstyle;				// Window style	RECT		WindowRect;				// Grabs Rectangle Upper Left / Lower Right Values	WindowRect.left=(long)0;			// Set Left Value To 0	WindowRect.right=(long)width;		// Set Right Value To Requested Width	WindowRect.top=(long)0;				// Set Top Value To 0	WindowRect.bottom=(long)height;		// Set Bottom Value To Requested Height	fullscreen=fullscreenflag;			// Set The Global Fullscreen Flag	hInstance			= GetModuleHandle(NULL);				// Grab An Instance For Our Window	wc.style			= CS_HREDRAW | CS_VREDRAW | CS_OWNDC;	// Redraw On Size, And Own DC For Window.	wc.lpfnWndProc		= (WNDPROC) WndProc;					// WndProc Handles Messages	wc.cbClsExtra		= 0;									// No Extra Window Data	wc.cbWndExtra		= 0;									// No Extra Window Data	wc.hInstance		= hInstance;							// Set The Instance	wc.hIcon			= LoadIcon(NULL, IDI_WINLOGO);			// Load The Default Icon	wc.hCursor			= LoadCursor(NULL, IDC_ARROW);			// Load The Arrow Pointer	wc.hbrBackground	= NULL;									// No Background Required For D3D	wc.lpszMenuName		= NULL;									// We Don't Want A Menu	wc.lpszClassName	= "Direct3D";							// Set The Class Name	if (!RegisterClass(&wc))									// Attempt To Register The Window Class	{		MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;											// Return FALSE	}	if (fullscreen)												// Fullscreen Mode?	{		dwExstyle=WS_EX_APPWINDOW;								// Window Extended style		dwstyle=WS_POPUP;										// Windows style		ShowCursor(FALSE);										// Hide Mouse Pointer	}	else	{		dwExstyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;			// Window Extended style		dwstyle=WS_OVERLAPPEDWINDOW;							// Windows style	}	AdjustWindowRectEx(&WindowRect, dwstyle, FALSE, dwExstyle);	// Adjust Window To True Requested Size	// Create The Window	if (!(hWnd=CreateWindowEx(	dwExstyle,							// Extended style For The Window								"Direct3D",							// Class Name								title,								// Window Title								dwstyle |							// Defined Window style								WS_CLIPSIBLINGS |					// Required Window style								WS_CLIPCHILDREN,					// Required Window style								0, 0,								// Window Position								WindowRect.right-WindowRect.left,	// Calculate Window Width								WindowRect.bottom-WindowRect.top,	// Calculate Window Height								NULL,								// No Parent Window								NULL,								// No Menu								hInstance,							// Instance								NULL)))								// Dont Pass Anything To WM_CREATE	{		KillD3DWindow();							// Reset The Display		MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE	}	if (!(hDC=GetDC(hWnd)))							// Did We Get A Device Context?	{		KillD3DWindow();								// Reset The Display		MessageBox(NULL,"Can't Create A Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE	}	pD3D = Direct3DCreate9( D3D_SDK_VERSION );		// Check For The Correct DirectX 3D version	if ( pD3D == NULL )	{		KillD3DWindow();							// Reset The Display		MessageBox(NULL,"Can't find D3D SDK Version 9.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE	}	D3DPRESENT_PARAMETERS d3dpp=					// d3dpp Tells Windows How We Want Things To Be	{		width,										// Back Buffer Width		height,										// Back Buffer Height		D3DFMT_R5G6B5,								// Back Buffer Format (Color Depth)		1,											// Back Buffer Count (Double Buffer)		D3DMULTISAMPLE_NONE,						// No Multi Sample Type		0,											// No Multi Sample Quality		D3DSWAPEFFECT_DISCARD,						// Swap Effect (Fast)		hWnd,										// The Window Handle		!fullscreen,								// Windowed or Fullscreen		TRUE,										// Enable Auto Depth Stencil  		D3DFMT_D16,									// 16Bit Z-Buffer (Depth Buffer)		0,											// No Flags		D3DPRESENT_RATE_DEFAULT,					// Default Refresh Rate		D3DPRESENT_INTERVAL_DEFAULT					// Default Presentation Interval (vertical sync)	};	// Check The Wanted Surface Format.	if ( FAILED( pD3D->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,									      d3dpp.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL,									      D3DRTYPE_SURFACE, d3dpp.AutoDepthStencilFormat ) ) )	{		KillD3DWindow();							// Reset The Display		MessageBox(NULL,"Can't Find Surface Format.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE	}	// Create The DirectX 3D Device 	if(FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,					 D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pD3DDevice ) ) )	{		KillD3DWindow();							// Reset The Display		MessageBox(NULL,"Can't Create DirectX 3D Device.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE	}	ShowWindow(hWnd,SW_SHOW);						// Show The Window	SetForegroundWindow(hWnd);						// Slightly Higher Priority	SetFocus(hWnd);									// Sets Keyboard Focus To The Window	ReSizeD3DScene(width, height);					// Set Up Our Perspective D3D Screen	if (!InitD3D())									// Initialize Our Newly Created D3D Window	{		KillD3DWindow();							// Reset The Display		MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);		return FALSE;								// Return FALSE	}	return TRUE;}LRESULT CALLBACK WndProc(	HWND	hWnd, 							UINT	uMsg, 							WPARAM	wParam, 							LPARAM	lParam ){    switch( uMsg )	{		case WM_ACTIVATE:							// Watch For Window Activate Message		{			if (!HIWORD(wParam))					// Check Minimization State			{				active=TRUE;						// Program Is Active			}			else			{				active=FALSE;						// Program Is No Longer Active			}			return 0;								// Return To The Message Loop		}		case WM_SYSCOMMAND:							// Intercept System Commands		{			switch (wParam)							// Check System Calls			{				case SC_SCREENSAVE:					// Screensaver Trying To Start?				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?				return 0;							// Prevent From Happening			}			break;									// Exit		}		case WM_CLOSE:								// Did We Receive A Close Message?		{			PostQuitMessage(0);						// Send A Quit Message			return 0;								// Jump Back		}		case WM_KEYDOWN:							// Is A Key Being Held Down?		{			keys[wParam] = TRUE;					// If So, Mark It As TRUE			return 0;								// Jump Back		}		case WM_KEYUP:								// Has A Key Been Released?		{			keys[wParam] = FALSE;					// If So, Mark It As FALSE			return 0;								// Jump Back		}		case WM_SIZE:								// Resize The Direct3D Window		{			if(!fullscreen)				ReSizeD3DScene(LOWORD(lParam), HIWORD(lParam));  // LoWord=Width, HiWord=Height			return 0;								// Jump Back		}	}	// Pass All Unhandled Messages To DefWindowProc	return DefWindowProc(hWnd,uMsg,wParam,lParam);}int WINAPI WinMain( HINSTANCE	hInstance,                    HINSTANCE	hPrevInstance,                    LPSTR		lpCmdLine,                    int			nCmdShow ){	MSG     msg;	BOOL	done=FALSE;								// Bool Variable To Exit Loop	// Ask The User Which Screen Mode They Prefer	if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)	{		fullscreen=FALSE;							// Windowed Mode	}	// Create Our DirectX 3D Window	if (!CreateD3DWindow("Apron Tutorials Direct3D Framework",640,480,fullscreen))	{		return 0;									// Quit If Window Was Not Created	}	while(!done)									// Loop That Runs While done=FALSE	{		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	// Is There A Message Waiting?		{			if (msg.message==WM_QUIT)				// Have We Received A Quit Message?			{				done=TRUE;							// If So done=TRUE			}			else									// If Not, Deal With Window Messages			{				TranslateMessage(&msg);				// Translate The Message				DispatchMessage(&msg);				// Dispatch The Message			}		}		else										// If There Are No Messages		{			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawD3DScene()			if ((active && !DrawD3DScene()) || keys[VK_ESCAPE])	// Active?  Was There A Quit Received?			{				done=TRUE;							// ESC or DrawD3DScene Signalled A Quit			}			if (keys[VK_F1])						// Is F1 Being Pressed?			{				keys[VK_F1]=FALSE;					// If So Make Key FALSE				KillD3DWindow();					// Kill Our Current Window				fullscreen=!fullscreen;				// Toggle Fullscreen / Windowed Mode				// Recreate Our DirectX 3D Window				if (!CreateD3DWindow("Apron Tutorials Direct3D Framework",640,480,fullscreen))				{					return 0;						// Quit If Window Was Not Created				}			}		}	}	// Shutdown	KillD3DWindow();	return (msg.wParam);							// Exit The Program}


[Edited by - TransistoR on June 11, 2006 10:53:19 AM]
Quote:Original post by overflowed_
You forgot to include link to the DirectX libraries


How to link to libraries then?
Quote:Original post by Introduction to 3d game programming with DirectX9

Note: The location of the DirectX directory DXSDK on your computer
may differ; it depends on the location that you specified during
installation.
Typically, the DirectX SDK installation will add these paths to VC++
for you. However, in case it doesn’t, you can do it manually as follows:
In VC++ 6.0 go to the menu and select Tools>Options>Directories
and enter the DirectX header file and library paths, as Figure I.3
shows.
In VC++ 7.0 go to the menu and select Tools>Options>Projects
Folder>VC++ Directories and enter the DirectX header and library
paths, as Figure I.4 shows.
Then, in order to build the sample programs, you will need to link the
library files d3d9.lib, d3dx9.lib, and winmm.lib into your project. Note
that winmm.lib isn’t a DirectX library file; it is the Windows multimedia
library file, and we use for its timer functions.
In VC++ 6.0 you can specify the library files to link in by going to
the menu and selecting Project>Settings>Link tab and then entering
the library names, as shown in Figure I.5.
Introduction xxi
Figure I.3: Adding the DirectX include
and library paths to VC++ 6.0
Figure I.4: Adding the
DirectX include and
library paths to VC++
7.0
In VC++ 7.0 you can specify the library files to link in by going to the
menu and selecting Project>Properties>Linker>Input Folder and
then entering the library names.

i donno about blood shed tho , it should be similar.

"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
So, I linked the libraries and i got more errors:
.drectve `%.*s' unrecognized (23 times)[Linker error] undefined reference to `Direct3DCreate9@4' [Linker error] undefined reference to `_except_list' (5 times)more undefined references to `_except_list' follow [Build Error]  [simple.exe] Error 1 

Compiler log looked like this:
Compiler: Default compilerBuilding Makefile: "C:\Documents and Settings\Administratorius\Desktop\Simple Basecode\Makefile.win"Executing  make...make.exe -f "C:\Documents and Settings\Administratorius\Desktop\Simple Basecode\Makefile.win" allwindres.exe -i simple_private.rc -I rc -o simple_private.res -O coff g++.exe main.o simple_private.res -o "simple.exe" -L"D:/Dev-Cpp/lib" -L"E:/DXSDK/Lib" D:/Dev-Cpp/lib/d3d9.lib D:/Dev-Cpp/lib/d3dx9.lib  Warning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedWarning: .drectve `%.*s' unrecognizedmain.o(.text+0x72c):main.cpp: undefined reference to `Direct3DCreate9@4'D:/Dev-Cpp/lib/d3dx9.lib(obj/i386/cpudetect.obj)(.text+0x9c):..\cpudetect.cpp: undefined reference to `_except_list'D:/Dev-Cpp/lib/d3dx9.lib(obj/i386/ssefasttable.obj)(.text+0x11):..\ssefasttable.cp: undefined reference to `_except_list'D:/Dev-Cpp/lib/d3dx9.lib(obj/i386/ssefasttable.obj)(.text+0x19):..\ssefasttable.cp: undefined reference to `_except_list'D:/Dev-Cpp/lib/d3dx9.lib(obj/i386/ssefasttable.obj)(.text+0x75):..\ssefasttable.cp: undefined reference to `_except_list'D:/Dev-Cpp/lib/d3dx9.lib(obj/i386/ssefasttable.obj)(.text+0x11):..\ssefasttable.cp: undefined reference to `_except_list'D:/Dev-Cpp/lib/d3dx9.lib(obj/i386/ssefasttable.obj)(.text+0x19):..\ssefasttable.cp: more undefined references to `_except_list' followmake.exe: *** [simple.exe] Error 1Execution terminated

Any suggestions why and how to fix these problems?
iam not sure , but it seems that it can't call the function . make sure you linked to (d3d9.lib, d3dx9.lib)
both.
"Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction."
I checked other projects and linked libraries the right way but I get same result.

This topic is closed to new replies.

Advertisement