# Project compiles, but won't link

## Recommended Posts

I've recreated the "Hello D3D" example from "Introduction to 3D Game Programming with DirectX 9.0c- A Shader Approach", in VC++05, with a couple of changes. The changes I made are to the structure of all the #includes, to make things a little simpler (to me), based on the approach of this gdnet article. I haven't changed any of the functions of the app, nor the macro used to handle the returns of D3D functions. After much fiddling, I've fixed all of the compile errors, and I thought I had it done when the ouput window told me: 1>------ Build started: Project: D3D Base Project, Configuration: Debug Win32 ------ 1>Compiling... 1>d3dApp.cpp 1>Linking... , but then I got a bunch of link errors, 2 of which look like this: 1>d3dApp.obj : error LNK2019: unresolved external symbol _DXTraceA@20 referenced in function "public: virtual void __thiscall D3DApp::initDirect3D(void)" (?initDirect3D@D3DApp@@UAEXXZ) 1>HelloD3D.obj : error LNK2001: unresolved external symbol _DXTraceA@20 The rest follow the same basic pattern. In this project, all returns from DX functions are handled with the macro HR(x), ie HR(gd3dDevice->Reset(&md3dPP)). The macro looks like this
#define HR(x)
{
HRESULT hr = x;
if(FAILED(hr))
{
DXTrace(__FILE__, __LINE__, hr, #x, TRUE);
}
}


So I think those link errors are saying that something is going wrong when DXTrace is called when handling the return of a DX function, which is being called from inside the function initDirect3D. Or something like that. But if DXTrace is being called, doesn't that mean that the DX functions are failing? I don't really know what's going on, can anyone help? cheers, metal

##### Share on other sites
The linker is responsible for building the application from object files. One object file asks for the DXTrace function 'just in case something fails' and the linker cannot locate that functionm so it creates a liner error.

##### Share on other sites
@Savage- yes, all the right libraries have been linked, which I know because I can compile the original version of the sample program, downloaded from the book's website.
@ToohrVyk- OK so that macro is in globals.h, and the functions that are listed in the error message (ie initDirect3D) are all in other files. Are you saying that the problem is something to do with the function initDirect3D not being able to get the function DXTrace from globals.h? Or is the problem that the project can't find DXTrace from whatever external location it's meant to be in?

cheers,
metal

##### Share on other sites
The linker says that it cannot find the definition of the function DXTrace. Where is that definition?

##### Share on other sites
Quote:
 Original post by ToohrVykThe linker says that it cannot find the definition of the function DXTrace. Where is that definition?

The book says, "Note: To use DXTrace, link dxerr9.lib and include dxerr9.h". I just checked again, and dxerr9.h is definitely included. dxerr9.lib should be linked, as long as it's in the folder <DXSDKpath>\Lib, which is the path listed in the version of the program that works. Is there a way to link a particular file, rather than telling VC++ which folder to look for that file in?
(In case you're wondering, DXTrace takes a DX error code and creates a messagebox with the file name, line number, error code, and error message)

cheers,
metal

##### Share on other sites
You can specify which libraries should be used by the linker, in the project properties dialog. I think I remember it being called 'additional dependencies' but I'm not sure.

You can also use pragma inside oneof your source files:
#pragma comment (lib, "dxerr9")

YAY! It works!!!
Thanks heaps.

cheers,
metal

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628293
• Total Posts
2981868

• 11
• 10
• 10
• 11
• 17