LNK 2005 and LNK1169 errors?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
GreatJake
Posts: 169
Joined: January 6th, 2013, 5:13 pm
Location: USA

LNK 2005 and LNK1169 errors?

Post by GreatJake » January 23rd, 2013, 4:25 am

So I have been working on a game for a while and this bug has been with me for a few days. All i did was add a header with global variables.. not good i know :( ... but i dont understand why im getting this error... The only way i know of to fix it is by going into the Chili Directx framework properties - Linker - Command Line and typing "/FORCE" but i don't feel like that is the correct solution.

If you are looking at my code sorry that its messy I have been working on keeping it clean.
Attachments
My Game.rar
(106.62 KiB) Downloaded 169 times

Conflictus
Posts: 53
Joined: January 7th, 2013, 8:09 am

Re: LNK 2005 and LNK1169 errors?

Post by Conflictus » January 23rd, 2013, 11:04 am

I decided to map out how the header files interact (excluding standard headers and the ones related to chili's framework).

The colored lines indicate a one way direction starting from the oval that shares the same color as the line. The only exception is the black line between player.h and attacks.h with a black line, which is bi-directional.

Unfortunately, I haven't figured it out yet, but i'll look into it again tomorrow.
Attachments
headers.png
headers.png (12 KiB) Viewed 4756 times

User avatar
GreatJake
Posts: 169
Joined: January 6th, 2013, 5:13 pm
Location: USA

Re: LNK 2005 and LNK1169 errors?

Post by GreatJake » January 23rd, 2013, 11:15 am

Wow thats a pretty cool idea! :D I accually fixed quite a few bugs changing the header file includes. But the error says something about windows.obj and chilis framework.exe

Conflictus
Posts: 53
Joined: January 7th, 2013, 8:09 am

Re: LNK 2005 and LNK1169 errors?

Post by Conflictus » January 23rd, 2013, 5:03 pm

Ahh.. I didn't see that there were changes made to Windows, D3DGraphics, etc.. I was operating under the assumption that the other files hadn't been touched and were merely part of the project. Otherwise i'd have included that in the diagram as well. In my defense it was around 6am when I posted to the forum. :P

Do you happen to have an earlier version that compiles without having to use "/FORCE"?

nG Inverse
Posts: 115
Joined: April 27th, 2012, 11:49 pm

Re: LNK 2005 and LNK1169 errors?

Post by nG Inverse » January 23rd, 2013, 5:12 pm

Do you mind posting the errors here?

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: LNK 2005 and LNK1169 errors?

Post by Musi » January 23rd, 2013, 7:56 pm

I think those errors are because you have defined global variables in a .h file. It's ok to declare functions in a header because your not defining them, but when you create a variable you're not just declaring it, you're actually defining it, which means you might #include the file multiple times thus violating the "one definition rule".

A way to fix this is to use the "extern" keyword, this tells the compiler the definition is somewhere else.

Code: Select all

extern int nKills;
extern int nEscapes;
extern float scoreRatio;
Then actually define the variables in a .cpp file.

Code: Select all

#include "Global.h"
int nKills;
int nEscapes;
float scoreRatio;
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

User avatar
GreatJake
Posts: 169
Joined: January 6th, 2013, 5:13 pm
Location: USA

Re: LNK 2005 and LNK1169 errors?

Post by GreatJake » January 23rd, 2013, 8:49 pm

Musi wrote:I think those errors are because you have defined global variables in a .h file. It's ok to declare functions in a header because your not defining them, but when you create a variable you're not just declaring it, you're actually defining it, which means you might #include the file multiple times thus violating the "one definition rule".

Edit: A way to fix this is to use the "extern" keyword, this tells the compiler the definition is somewhere else.

Code: Select all

extern int nKills;
extern int nEscapes;
extern float scoreRatio;
Then actually define the variables in a .cpp file.

Code: Select all

#include "Global.h"
int nKills;
int nEscapes;
float scoreRatio;
Thank You! That fixed everything. It seems like a waste of a file but i guess you have to do what you have to do :P. And thank you everyone else.

And for future reference here are the errors.

Code: Select all

Error	25	error LNK2005: "int nKills" (?nKills@@3HA) already defined in Game.obj	C:\Users\---------\Documents\C++ Toutorial Stuff\My Game\Chili DirectX Framework\Windows.obj	Chili DirectX Framework

Code: Select all

Error	26	error LNK2005: "int nEscapes" (?nEscapes@@3HA) already defined in Game.obj	C:\Users\-----------\Documents\C++ Toutorial Stuff\My Game\Chili DirectX Framework\Windows.obj	Chili DirectX Framework

Code: Select all

Error	27	error LNK2005: "float scoreRatio" (?scoreRatio@@3MA) already defined in Game.obj	C:\Users\---------\Documents\C++ Toutorial Stuff\My Game\Chili DirectX Framework\Windows.obj	Chili DirectX Framework

Code: Select all

Error	28	error LNK1169: one or more multiply defined symbols found	C:\Users\-----------\Documents\C++ Toutorial Stuff\My Game\Debug\Chili DirectX Framework.exe	1	1	Chili DirectX Framework

Musi
Posts: 106
Joined: November 25th, 2012, 1:06 am

Re: LNK 2005 and LNK1169 errors?

Post by Musi » January 23rd, 2013, 8:59 pm

No problem, but does the code work?

After looking at Conflictus' diagram i noticed that Player.h includes Attack.h and Attack.h inlcudes Player.h. I didn't think you could do this because it creates a never ending #include recursion.

Player includes Attack, which includes Player, which includes Attack...etc.
Musi

There are 10 types of people that understand binary.
Those that do, and those that don't.

User avatar
GreatJake
Posts: 169
Joined: January 6th, 2013, 5:13 pm
Location: USA

Re: LNK 2005 and LNK1169 errors?

Post by GreatJake » January 23rd, 2013, 9:47 pm

Huh... i didn't notice that. It compiles and runs fine and I just ran the .exe it creates for you but that crashes. Maybe I changed the compilers settings by accident to "force" it to compile? Ill try resetting it to default settings.

User avatar
GreatJake
Posts: 169
Joined: January 6th, 2013, 5:13 pm
Location: USA

Re: LNK 2005 and LNK1169 errors?

Post by GreatJake » January 24th, 2013, 12:30 am

Sorry scratch that, i cant run anybodys game that uses chilies framework. So I have no idea why it works.

Post Reply