Sign in to follow this  
Migi0027

C++ Including causes redifinition

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
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
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
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
Manually defined your entry point means what? Did you create the necessary function, or did you set the "entry point" in your linker settings?

If the latter, please be aware this is very advanced functionality and almost certainly not what you should be doing. [url="http://msdn.microsoft.com/en-us/library/f9t8842e(v=vs.80).aspx"]For example[/url]:
[quote]
The /ENTRY option specifies an entry point function as the starting address for an .exe file or DLL.

The function must be defined with the __stdcall calling convention. The parameters and return value must be defined as documented in the Win32 API for WinMain (for an .exe file) or DllEntryPoint (for a DLL). [b]It is recommended that you let the linker set the entry point so that the C run-time library is initialized correctly, and C++ constructors for static objects are executed.[/b]

By default, the starting address is a function name from the C run-time library. The linker selects it according to the attributes of the program, as shown in the following table.
[/quote]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this