Reputation: 155
I'm writing a game for Windows 7 and 8. I've been using VS2012. So basically I'm trying to get my head around the Windows SDK. d3dX10math has been replaced, I've come to terms with that, and I've included DirectXMath.h where necessary.
The problem comes, as it so often does, with the linker. It's not linking to the necessary library. They are right there in external dependencies (I'm assuming that the old d3dx10math.lib has been replaced by these .inl files?). I can't find an equivalent .lib file so that's what I'm assuming.
It just doesn't want to actually link to them. I've searched high and low online and nobody seems to have asked this question. I feel like I've missed something?
#ifndef _CDEVICE_H_
#define _CDEVICE_H_
//#include <vector>
#pragma once
//#pragma comment(lib, "dxgi.lib")
//#pragma comment(lib, "d3d11.lib")
#include <dxgi.h>
#include <d3d11.h>
#include <DirectXMath.h>
using namespace DirectX;
static class cDevice
{
public:
cDevice();
cDevice(const cDevice&);
~cDevice();
private:
static ID3D11Device* device;
static XMFLOAT2 float2;
} device;
#endif
and then I get this linker error
1>cDevice.obj : error LNK2001: unresolved external symbol "private: static struct DirectX::XMFLOAT2 cDevice::float2" (?float2@cDevice@@0UXMFLOAT2@DirectX@@A)
Upvotes: 0
Views: 436
Reputation: 41057
static XMFLOAT2 float2;
in your header as a class member requires you have a .cpp file (say CDevice.cpp) in your project that has XMFLOAT2 Device::float2( 0, 0 );
--or whatever initial value you expect to have--in it to actually declare the variable. That makes CDevice::float2
a static member variable of the class. You have declared your CDevice to have a static ID3D11Device* device;
, which again would require a .cpp file with ID3D11Device* CDevice::device = nullptr;
in it to link.
Also, don't put using namespace statements in your headers. They are great in .cpp files, but in headers you should stick with full names like: DirectX::XMFLOAT2
.
A .h like this:
static class cDevice
{
public:
cDevice();
cDevice(const cDevice&);
~cDevice();
private:
static ID3D11Device* device;
static DirectX::XMFLOAT2 float2;
} device;
would require a .cpp file like this:
#include "CDevice.h" using namespace DirectX;
using namespace DirectX;
ID3D11Device* CDevice::device = nullptr;
XMFLOAT2 CDevice::float2(0, 0);
And if you ever included that .h in more than one .cpp file you'd find that every one has it's own unrelated CDevice copy in it.
I don't know why you'd want to do any of that as that makes little sense as a design (you should have non-static variables in your class CDevice
, or you should be using a namespace CDevice
instead since you aren't actually using object encapsulation, or maybe make a singleton). You should probably read a primer on C++ to get the basics of these as it has nothing at all to do with DirectX in particular, and you appear very confused about the use of the (admittedly heavily overloaded) keyword static
.
I would strongly suggest you take a look at using the SimpleMath wrapper for DirectXMath in the DirectX Tool Kit, and really the rest of the DirectX Tool Kit too.
I'd also suggesting moving to VS 2013 Community Edition rather than VS 2012 (Express for Windows Desktop?), and using the Direct3D Win32 Game template as you want to support Windows 7.
Upvotes: 1