C++ Including causes redifinition

Started by
12 comments, last by rip-off 11 years, 9 months ago
Hi guys, im currently having a problem with including:

Small diagram:

Editor.h
|
|
System.h
/ | \
/ | \
/ | \
EDIT: The spaces wont apply!!! So the diagram is bugged.. But the point is that Editor.h includes System.h which includes loads of different headers...

The system.h includes loads of different headers. All of theese headers have including guards, but still, i get redifinition errors in my Editor.obj(when debugging) which came from the system.h

E.g.

In system.h:
class SHADER
{
public:bool CompileFromShader; //If you put this value to false, you are as well fucking up this...
public:LPCSTR ShaderFileName;
};

And then it says, that this has been redefined in the Editor.obj (Editor.h)

Please help me.

Best Regards
Miguel Petersen

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Advertisement
Just to be perfectly clear, both editor.h and system.h have include guards? You said all the others do.

If your on Visual Studio you can use the [source lang="cpp]# pragma once[/source] directive instead of:[source lang="cpp]
# ifndef __INCLUDE_H_
# define __INCLUDE_H_ 1

/*
** include.h - a collection of useful headers
*/

# endif /* __INCLUDE_H_ */

[/source]I tend not to like the first because it's not really a standard directive.

Failing that, I've found that I get compiling errors if I don't leave a blank line at the end of my files. I'm not sure of the technical reason why.

I hope this helps.

Also, you haven't accidently copied the class definition into one of the source files have you? It seems stupid I was adding to my engine the other day and I just started in a source file before I moved parts to a header.
Please post the actual error you are receiving. The error contains important information that will help pinpoint the cause of the problem.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Errors as requested:

1>main.obj : error LNK2005: "void __cdecl EnableAA(struct ID3D11Device *)" (?EnableAA@@YAXPAUID3D11Device@@@Z) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl CalcCamera(float,float)" (?CalcCamera@@YAXMM@Z) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl RenderFrame(void)" (?RenderFrame@@YAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl CleanD3D(void)" (?CleanD3D@@YAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl InitGraphics(void)" (?InitGraphics@@YAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl InitPipeline(void)" (?InitPipeline@@YAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl Cube3D::LoopRender(void)" (?LoopRender@Cube3D@@YAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl InitD3D(struct HWND__ *)" (?InitD3D@@YAXPAUHWND__@@@Z) already defined in Editor.obj
1>main.obj : error LNK2005: "struct ID3D11DepthStencilView * zbuffer" (?zbuffer@@3PAUID3D11DepthStencilView@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct ID3D11RenderTargetView * backbuffer" (?backbuffer@@3PAUID3D11RenderTargetView@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct IDXGISwapChain * swapchain" (?swapchain@@3PAUIDXGISwapChain@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct ID3D11Device * dev" (?dev@@3PAUID3D11Device@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct ID3D11DeviceContext * devcon" (?devcon@@3PAUID3D11DeviceContext@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct ID3D11InputLayout * pLayout" (?pLayout@@3PAUID3D11InputLayout@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct ID3D11Buffer * pCBuffer" (?pCBuffer@@3PAUID3D11Buffer@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct ID3D11VertexShader * pVS" (?pVS@@3PAUID3D11VertexShader@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct ID3D11PixelShader * pPS" (?pPS@@3PAUID3D11PixelShader@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "unsigned long * CubeIndices" (?CubeIndices@@3PAKA) already defined in Editor.obj
1>main.obj : error LNK2005: "bool UseAA" (?UseAA@@3_NA) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl EnableAA(struct ID3D11Device *)" (?EnableAA@@$$FYAXPAUID3D11Device@@@Z) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl CalcCamera(float,float)" (?CalcCamera@@$$FYAXMM@Z) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl RenderFrame(void)" (?RenderFrame@@$$FYAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl CleanD3D(void)" (?CleanD3D@@$$FYAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl InitGraphics(void)" (?InitGraphics@@$$FYAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl InitPipeline(void)" (?InitPipeline@@$$FYAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl Cube3D::LoopRender(void)" (?LoopRender@Cube3D@@$$FYAXXZ) already defined in Editor.obj
1>main.obj : error LNK2005: "void __cdecl InitD3D(struct HWND__ *)" (?InitD3D@@$$FYAXPAUHWND__@@@Z) already defined in Editor.obj
1>main.obj : error LNK2005: "struct D3DXMATRIX matFinal" (?matFinal@@3UD3DXMATRIX@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct D3DXMATRIX matProjection" (?matProjection@@3UD3DXMATRIX@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct D3DXMATRIX matRotate" (?matRotate@@3UD3DXMATRIX@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct D3DXMATRIX matView" (?matView@@3UD3DXMATRIX@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct CUBE * CubeVertices" (?CubeVertices@@3PAUCUBE@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct CBUFFER cBuffer" (?cBuffer@@3UCBUFFER@@A) already defined in Editor.obj
1>main.obj : error LNK2005: "struct D3DXMATRIX matPosition" (?matPosition@@3UD3DXMATRIX@@A) already defined in Editor.obj
1>C:\Users\Utilizador\Documents\Visual Studio 11\Projects\Cube3D\Debug\CuboidEngine.exe : fatal error LNK1169: one or more multiply defined symbols found

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Are you sure you're not accidentally including a .cpp file instead of an .h file? The errors indicate that the linker found multiple copies of certain functions and variables.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Also check any non-template, non-member inline functions are labeled with the inline keyword.
Is there any way that i can generate a kind of graph of all the including?

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

Maybe i solved it, but now it cannot find my entry point. I have defined it in the properties->Linker->All Options->Entry main.cpp, but it wont accept it, it gives me just one external error now:

Error 31 error LNK2001: unresolved external symbol _main.cpp

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

The entry point is a function name, not a file name. You should not manually set the entry point unless you are 100% sure of what you are doing. Have you set the correct subsystem? Do you have an implementation of main() or WinMain()? They must be free functions and not class members. Perhaps you have made a minor error in the signature?
I have a function: int main() i use WINDOWS as a subsystem

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

This topic is closed to new replies.

Advertisement