-
September 19th, 2012, 01:24 AM
#1
one header file defines a struct and the other uses it.
Code:
// mesh.h
struct D3DXMESHCONTAINER_DERIVED
{
};
// allocmeshhierarchy.h
#include "mesh.h"
void GenerateSkinnedMesh (LPDIRECT3DDEVICE9 pDevice, D3DXMESHCONTAINER_DERIVED* pMeshContainer);
[translated]
error C2011: D3DXFRAME_DERIVED repeated definition of d: \ users \ documents \ visual studio 2010 \ projects \ perfectsim v5.0 \ perfectsim v5.0 \ mesh \ mesh.h the 11 1 PerfectSim V5.0
What is correct linkage method?
Thanks
Jack
Last edited by lucky6969b; September 19th, 2012 at 02:16 AM.
-
September 19th, 2012, 02:39 AM
#2
Re: one header file defines a struct and the other uses it.
Originally Posted by lucky6969b
error C2011: D3DXFRAME_DERIVED repeated definition of d: \ users \ documents \ visual studio 2010 \ projects \ perfectsim v5.0 \ perfectsim v5.0 \ mesh \ mesh.h the 11 1 PerfectSim V5.0
What is correct linkage method?
Thanks
Jack
What does linkage have to do with this compiler error C2011?
And, BTW, I don't see any D3DXFRAME_DERIVED type in the code snippets you have posted.
Victor Nijegorodov
-
September 19th, 2012, 03:00 AM
#3
Re: one header file defines a struct and the other uses it.
What is correct linkage method?
Where are your include guards for that header? That is a compiler error, and the reason is more than likely that you do not have include guards to prevent the definition being encountered two (or more times) per compilation unit.
Regards,
Paul McKenzie
-
September 19th, 2012, 03:17 AM
#4
Re: one header file defines a struct and the other uses it.
Sorry, I have solved it myself
First
AllocMeshHierarchy.h
#include "mesh.h"
Second
AllocMeshHierarchy.cpp
#include "AllocMeshHierarchy.h"
third
mesh.h
struct D3DXMESHCONTAINER_DERIVED //etc
Thanks both of you
Jack
Last edited by lucky6969b; September 19th, 2012 at 03:24 AM.
-
September 19th, 2012, 06:46 AM
#5
Re: one header file defines a struct and the other uses it.
You don't have include guards in your header, which means each symbol defined there will be created once in each translation unit (cpp file) that includes the header. You need either this:
Code:
#pragma once
struct D3DXMESHCONTAINER_DERIVED
{
};
or
Code:
#ifndef _THEHEADER_
#define _THEHEADER_
struct D3DXMESHCONTAINER_DERIVED
{
};
#endif // end of header
-
September 19th, 2012, 09:23 AM
#6
Re: one header file defines a struct and the other uses it.
Originally Posted by lucky6969b
Sorry, I have solved it myself
That is no solution. All you're doing is delaying the inevitable, and that is two or more inclusions of the header file in a single compilation unit.
The actual solution is to use include guards, as cilu and myself have pointed out. With a more complex program, you would go crazy trying to figure out what header goes first, second, third, etc. without include guards. You may not even have a scenario where you can guarantee that the header is seen only once by the compiler, so how are you going to solve that issue without using include guards?
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|