Linker Nightmares

Started by
11 comments, last by AverageMidget 12 years, 6 months ago
I moved on to another project, and are running into Linker problems again! Again, I[color="#1C2837"] am running on Visual C++ Express with the June 2010 release of DirectX.

All the libraries added are listed below the output below:

This time I get:
1>------ Build started: Project: Circle, Configuration: Release Win32 ------
1>Circle.obj : error LNK2001: unresolved external symbol "public: long __thiscall CD3DFont::InitDeviceObjects(struct IDirect3DDevice9 *)" (?InitDeviceObjects@CD3DFont@@QAEJPAUIDirect3DDevice9@@@Z)
1>Circle.obj : error LNK2001: unresolved external symbol "void __cdecl D3DUtil_InitLight(struct _D3DLIGHT9 &,enum _D3DLIGHTTYPE,float,float,float)" (?D3DUtil_InitLight@@YAXAAU_D3DLIGHT9@@W4_D3DLIGHTTYPE@@MMM@Z)
1>D3DApplication.obj : error LNK2001: unresolved external symbol "public: long __thiscall CD3DMesh::Create(struct IDirect3DDevice9 *,char *)" (?Create@CD3DMesh@@QAEJPAUIDirect3DDevice9@@PAD@Z)
1>D3DApplication.obj : error LNK2001: unresolved external symbol "public: long __thiscall CD3DFrame::Render(struct IDirect3DDevice9 *,int,int)" (?Render@CD3DFrame@@QAEJPAUIDirect3DDevice9@@HH@Z)
1>D3DApplication.obj : error LNK2001: unresolved external symbol "public: long __thiscall CD3DFrame::RestoreDeviceObjects(struct IDirect3DDevice9 *)" (?RestoreDeviceObjects@CD3DFrame@@QAEJPAUIDirect3DDevice9@@@Z)
1>D3DApplication.obj : error LNK2001: unresolved external symbol "long __cdecl D3DUtil_SetDeviceCursor(struct IDirect3DDevice9 *,struct HICON__ *)" (?D3DUtil_SetDeviceCursor@@YAJPAUIDirect3DDevice9@@PAUHICON__@@@Z)
1>eisdk.lib(d3dfile.obj) : error LNK2001: unresolved external symbol _D3DXLoadMeshFromX@28
1>eisdk.lib(d3dfile.obj) : error LNK2001: unresolved external symbol _D3DXLoadMeshFromXof@28
1>eisdk.lib(d3dfile.obj) : error LNK2001: unresolved external symbol _D3DXComputeNormals@4
1>C:\Users\Pedro\Documents\Visual Studio 2010\Projects\Circle\Release\Circle.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Character set is Multibyte since I'm compiling older code

I changed the RunTime Library to /MT (Multithreaded) and are running a Release build


These are the classes under Linker/Input/Additional Dependencies:
libcmt.lib
dinput8.lib
d3d9.lib
dxguid.lib
kernel32.lib
user32.lib
gdi32.lib
comdlg32.lib
ole32.lib
winmm.lib
psapi.lib

These are the classes under Linker/Input/Ignore:
libc.lib
msvcrt.lib
libcd.lib
libcp.lib
libcmtd.lib
msvcrtd.lib

Under Linker/General/ Additional Library Directories:
C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86
C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x64
C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Lib

Under VC++ Directories:
Include:
C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include
C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Include
Library Directories:
C:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86
C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Include


Thanks!
Advertisement
I'll try and help in a way that'll help you figure these things out for yourself.

If you look at the msdn entry for D3DXLoadMeshFromX function (which is one of your linker errors) and you scroll down, you'll see the requirments. The library is D3dx9.lib


Is that lib included in your dependencies list?

EDIT:
I'll add that unresolved external symbol basically means it can't find the proper signature of the following function(s), so you have to tell the linker where to find it. In case you were confused by that part.

I'll try and help in a way that'll help you figure these things out for yourself.

If you look at the msdn entry for D3DXLoadMeshFromX function (which is one of your linker errors) and you scroll down, you'll see the requirments. The library is D3dx9.lib


Is that lib included in your dependencies list?

EDIT:
I'll add that unresolved external symbol basically means it can't find the proper signature of the following function(s), so you have to tell the linker where to find it. In case you were confused by that part.



AverageMidget, I want to be able to figure these things out for myself and as such I appreciate the fact that you give explanations as opposed to just giving an answer.

Ok, so in the case of D3DXLoadMeshFromX function, the closest that I could find to that function in the project code was the LoadMesh function in d3dfile.h
I added d3dx9.lib to the linker requirements to no avail. Now, the msdn entry that you referenced says that d3dx9Mesh.h is also a requirement. I downloaded this header file from Koders.com, added it to the header's directory and #included it in the file where I'm actually loading the mesh file (However, the call that I'm making is: bool D3DModel::Load(LPCTSTR xFileName, LPDIRECT3DDEVICE9 dev) so I'm a bit confused how the D3DXLoadMeshFromX function is being called). What am I doing wrong?

From reading some other posts it seems that sometimes you have to also add external .cpp files to the project such as d3dapp.cpp (not just headers and libraries), could that be the case here?
In particular I read: http://www.gamedev.n...ng-a-dx-sample/ and tried importing the .cpp files suggested (d3dapp.cpp, d3dfont.cpp, d3denumeration.cpp) however, those files were not in my sdk download and if I try downloading them from Koders.com, the files seem to be out of date as they are calling non-existing headers.

Thanks, and again excuse my noobishness.
...(However, the call that I'm making is: bool D3DModel::Load(LPCTSTR xFileName, LPDIRECT3DDEVICE9 dev) so I'm a bit confused how the D3DXLoadMeshFromX function is being called). What am I doing wrong?


I would imagine that D3DXLoadMeshFromX is being called from within the D3DModel::Load method. I, however, am having a hard time finding that. It seems like that method (and most of the other methods listed in your linker errors) are from some DirectX SDK samples. Not actual documented Microsoft source.

[color="#1C2837"]From reading some other posts it seems that sometimes you have to also add external .cpp files to the project such as d3dapp.cpp (not just headers and libraries), could that be the case here?


That is sometimes the case. If the author of the code you're trying to use left it as a plain .cpp file (not compiled into a .dll or .lib), you would add that to your project and include the header, where you want to use the code.

In my poking around, I found the [color="#1C2837"]CD3DMesh[color="#1C2837"] and [color="#1C2837"]CD3DFrame[color="#1C2837"] classes defined in a file named d3dfile.cpp. Also, these samples appear to be part of the DirectX 9 SDK samples.

[quote name='pmachin' timestamp='1319348995' post='4875537']...(However, the call that I'm making is: bool D3DModel::Load(LPCTSTR xFileName, LPDIRECT3DDEVICE9 dev) so I'm a bit confused how the D3DXLoadMeshFromX function is being called). What am I doing wrong?


I would imagine that D3DXLoadMeshFromX is being called from within the D3DModel::Load method. I, however, am having a hard time finding that. It seems like that method (and most of the other methods listed in your linker errors) are from some DirectX SDK samples. Not actual documented Microsoft source.

[color="#1C2837"]From reading some other posts it seems that sometimes you have to also add external .cpp files to the project such as d3dapp.cpp (not just headers and libraries), could that be the case here?


That is sometimes the case. If the author of the code you're trying to use left it as a plain .cpp file (not compiled into a .dll or .lib), you would add that to your project and include the header, where you want to use the code.

In my poking around, I found the [color="#1C2837"]CD3DMesh[color="#1C2837"] and [color="#1C2837"]CD3DFrame[color="#1C2837"] classes defined in a file named d3dfile.cpp. Also, these samples appear to be part of the DirectX 9 SDK samples.
[/quote]

You we're right, most of the problem emerged due to d3dfile.cpp. Specifically, the lib included in my sample project not being recent. Instead, I had to download an old copy of d3dfile.cpp and update its structures. After it took me all day to do this, I saw that another person had posted the solution to this exact same problem in gamedev! Well, at least I learned something :) (http://www.gamedev.n...les-with-dx90c/)

Now, I finally got the project to compile and link (at least in release mode) and I just get a black screen. I tracked down the problem to the GetAdapterCount() always returning zero and therefore not building a device list. I looked this up online, but I only found some reference to the OS sometimes being at fault in some systems?! Not sure where to go from here.


HRESULT D3DApplication::BuildDeviceList()
{
const DWORD dwNumDeviceTypes = 2;
const TCHAR* strDeviceDescs[] = { _T("HAL"), _T("REF") };
const D3DDEVTYPE DeviceTypes[] = { D3DDEVTYPE_HAL, D3DDEVTYPE_REF };

BOOL bHALExists = FALSE;
//BOOL bHALIsWindowedCompatible = FALSE;
BOOL bHALIsDesktopCompatible = FALSE;
BOOL bHALIsSampleCompatible = FALSE;

/* debug code
UINT adapterCount = m_pD3D->GetAdapterCount();
if(adapterCount == 0)
{
return 0; <<<<<-------always exists here
}else if(adapterCount == 1)
{
return 1;
}*/

// Loop through all the adapters on the system (usually, there's just one
// unless more than one graphics card is present).
for( UINT iAdapter = 0; iAdapter < m_pD3D->GetAdapterCount(); iAdapter++ )
{
// Fill in adapter info

.........

This topic is closed to new replies.

Advertisement