Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


C++ Including causes redifinition


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Migi0027 =A=   Crossbones+   -  Reputation: 1971

Like
0Likes
Like

Posted 04 July 2012 - 01:59 PM

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, 04 July 2012 - 02:02 PM.

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


Sponsor:

#2 BinaryPhysics   Members   -  Reputation: 294

Like
1Likes
Like

Posted 04 July 2012 - 02:34 PM

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, 06 July 2012 - 06:06 AM.


#3 ApochPiQ   Moderators   -  Reputation: 16078

Like
1Likes
Like

Posted 04 July 2012 - 02:53 PM

Please post the actual error you are receiving. The error contains important information that will help pinpoint the cause of the problem.

#4 Migi0027 =A=   Crossbones+   -  Reputation: 1971

Like
0Likes
Like

Posted 04 July 2012 - 03:05 PM

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

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


#5 ApochPiQ   Moderators   -  Reputation: 16078

Like
0Likes
Like

Posted 04 July 2012 - 03:34 PM

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.

#6 e‍dd   Members   -  Reputation: 2105

Like
1Likes
Like

Posted 04 July 2012 - 06:43 PM

Also check any non-template, non-member inline functions are labeled with the inline keyword.

#7 Migi0027 =A=   Crossbones+   -  Reputation: 1971

Like
0Likes
Like

Posted 05 July 2012 - 01:07 AM

Is there any way that i can generate a kind of graph of all the including?

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


#8 Migi0027 =A=   Crossbones+   -  Reputation: 1971

Like
0Likes
Like

Posted 05 July 2012 - 01:31 AM

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

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


#9 rip-off   Moderators   -  Reputation: 8522

Like
2Likes
Like

Posted 05 July 2012 - 01:58 AM

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?

#10 Migi0027 =A=   Crossbones+   -  Reputation: 1971

Like
0Likes
Like

Posted 05 July 2012 - 02:30 AM

I have a function: int main() i use WINDOWS as a subsystem

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


#11 Migi0027 =A=   Crossbones+   -  Reputation: 1971

Like
0Likes
Like

Posted 05 July 2012 - 02:31 AM

I removed my entry point, but now this comes up:
Error 31 error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


#12 RulerOfNothing   Members   -  Reputation: 1164

Like
0Likes
Like

Posted 05 July 2012 - 05:12 AM

If you're making a windows program you need to have a WinMain function rather than a main function.

#13 Migi0027 =A=   Crossbones+   -  Reputation: 1971

Like
0Likes
Like

Posted 05 July 2012 - 06:07 AM

I manually defined my entry point and now it worked, but thanks!

Hi! Cuboid Zone
The Rule: Be polite, be professional, but have a plan to steal all their shaders!


#14 rip-off   Moderators   -  Reputation: 8522

Like
1Likes
Like

Posted 05 July 2012 - 08:40 AM

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. For example:

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). 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.

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS