Jump to content
  • Advertisement
Sign in to follow this  
Migi0027

C++ Including causes redifinition

This topic is 2201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 Edited by Migi0027

Share this post


Link to post
Share on other sites
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. Edited by BinaryPhysics

Share this post


Link to post
Share on other sites
Please post the actual error you are receiving. The error contains important information that will help pinpoint the cause of the problem.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Also check any non-template, non-member inline functions are labeled with the inline keyword.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!