Jump to content

  • Log In with Google      Sign In   
  • Create Account


Vertex declarations give linkage errors


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Veil   Members   -  Reputation: 143

Like
0Likes
Like

Posted 04 May 2012 - 11:46 AM

I'm not sure if this is the right forum category for this(since linkage errors aren't only for DirectX)

The problem is,in my vertex declaration header:
#pragma once
#include <d3dx9.h>
void InitAllVertexDeclarations();
void DestroyAllVertexDeclarations();
struct VertexPos
{
VertexPos():pos(0.0f, 0.0f, 0.0f){}
VertexPos(float x, float y, float z):pos(x,y,z){}
VertexPos(const D3DXVECTOR3& v):pos(v){}
D3DXVECTOR3 pos;
static IDirect3DVertexDeclaration9* Decl;
};
struct VertexCol
{
VertexCol():pos(0.0f, 0.0f, 0.0f),col(0x00000000){}
VertexCol(float x, float y, float z, D3DCOLOR c):pos(x,y,z), col(c){}
VertexCol(const D3DXVECTOR3& v, D3DCOLOR c):pos(v),col(c){}
D3DXVECTOR3 pos;
D3DCOLOR    col;
static IDirect3DVertexDeclaration9* Decl;
};
struct VertexPN
{
VertexPN()
  :pos(0.0f, 0.0f, 0.0f),
  normal(0.0f, 0.0f, 0.0f){}
VertexPN(float x, float y, float z,
  float nx, float ny, float nz):pos(x,y,z), normal(nx,ny,nz){}
VertexPN(const D3DXVECTOR3& v, const D3DXVECTOR3& n)
  :pos(v),normal(n){}
D3DXVECTOR3 pos;
D3DXVECTOR3 normal;
static IDirect3DVertexDeclaration9* Decl;
};
struct VertexPNT
{
VertexPNT()
  :pos(0.0f, 0.0f, 0.0f),
  normal(0.0f, 0.0f, 0.0f),
  tex0(0.0f, 0.0f){}
VertexPNT(float x, float y, float z,
  float nx, float ny, float nz,
  float u, float v):pos(x,y,z), normal(nx,ny,nz), tex0(u,v){}
VertexPNT(const D3DXVECTOR3& v, const D3DXVECTOR3& n, const D3DXVECTOR2& uv)
  :pos(v),normal(n), tex0(uv){}
D3DXVECTOR3 pos;
D3DXVECTOR3 normal;
D3DXVECTOR2 tex0;
static IDirect3DVertexDeclaration9* Decl;
};
IDirect3DVertexDeclaration9* VertexPos::Decl = 0;
IDirect3DVertexDeclaration9* VertexCol::Decl = 0;
IDirect3DVertexDeclaration9* VertexPN::Decl  = 0;
IDirect3DVertexDeclaration9* VertexPNT::Decl = 0;

i have used

IDirect3DVertexDeclaration9* VertexPos::Decl = 0;
IDirect3DVertexDeclaration9* VertexCol::Decl = 0;
IDirect3DVertexDeclaration9* VertexPN::Decl  = 0;
IDirect3DVertexDeclaration9* VertexPNT::Decl = 0;
and then the header is used by the Terrain header,which in turn is used by the Camera header.Now i checked all other possibilities,there is no other place where this problem could originate.The problem is IntelliSense says all these structs are alredy defined in the .obj-s where ''Vertex.h'' is used:

error.png

Sponsor:

#2 MJP   Moderators   -  Reputation: 10854

Like
0Likes
Like

Posted 04 May 2012 - 03:03 PM

IDirect3DVertexDeclaration9* VertexPos::Decl = 0;
IDirect3DVertexDeclaration9* VertexCol::Decl = 0;
IDirect3DVertexDeclaration9* VertexPN::Decl  = 0;
IDirect3DVertexDeclaration9* VertexPNT::Decl = 0;

You can't define static variables like this in a header file, otherwise they will get defined in every translation unit that includes the header (which is why you get the "already defined error"). You need to define them in a cpp file.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS