Recommended Posts

'lo everyone. I'm having a really annoying problem with a game engine that I'm developing and what's possibly more annoying is the fact that the problems are to do with how I have used C++. I use Dev-C++ 4.9.9.2. I have two projects, one containing D3D_Engine.cpp and D3D_Engine.hpp (the project files) and a test project, containing D3D_Engine.cpp and another file called test.cpp. Both test.cpp and D3D_Engine.cpp include the header file (D3D_Engine.hpp), which contains function prototypes which have their code in D3D_Engine.cpp. In D3D_Engine.hpp I have some variables declared as extern; ofstream d3d_err (which I have no problems with) and IDirect3D9 *g_d3dObj. I then have these variables defined in D3D_Engine.cpp, and I initialise g_d3dObj in that file. The problem that I'm having occurs in the test project. Whenever I try to compile, I get an error message saying that there is a multiple definition of g_d3dObj. I've looked everywhere in D3D_Engine.cpp, and I can't find any multiple definitions. It could be to do with my understanding of C++ linkage. I think that I've probably made no sense there, so I'll give some source...
//D3D_Engine.hpp
//GLOBALS
extern ofstream d3d_err;
extern IDirect3D9 *g_d3dObj;

//D3D_Engine.cpp
//GLOBALS
ofstream d3d_err;
IDirect3D9 *g_d3dObj = NULL;

I'll only give that part of the code, because that's all (I think) is relevant. One final note: test.cpp doesn't make any reference to g_d3dObj at all, apart from calling functions that use it.

Share on other sites
Maybe I'm misunderstanding you, but if you want to use your engine in more than one project, you'd be better off making it a static library, so you can share it between different projects.

If you're already doing this, then I reckon this is why you've having problems, because you've got D3D_Engine.cpp in both files.

Also, just to make sure, do you definitely have include guards in the header file? i.e.

#ifndef DIRECT3DENGINE_H#define DIRECT3DENGINE_H//Everything in the header goes here#endif

Share on other sites
I want to make my engine available to others, yes. I probably will make a static library. I do have include guards. What do you mean by "you've got D3D_Engine.cpp in both files"? Both projects?
EDIT: I made a static library, and linked it with my test project, and it still gave the same error.

[Edited by - AD10419 on June 3, 2005 10:02:39 AM]

Create an account

Register a new account

• Forum Statistics

• Total Topics
628307
• Total Posts
2981972

• 9
• 13
• 11
• 12
• 11