LNK 2005 and LNK1169 errors?
LNK 2005 and LNK1169 errors?
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.
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
-
- Posts: 53
- Joined: January 7th, 2013, 8:09 am
Re: LNK 2005 and LNK1169 errors?
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.
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 (12 KiB) Viewed 4756 times
Re: LNK 2005 and LNK1169 errors?
Wow thats a pretty cool idea! I accually fixed quite a few bugs changing the header file includes. But the error says something about windows.obj and chilis framework.exe
-
- Posts: 53
- Joined: January 7th, 2013, 8:09 am
Re: LNK 2005 and LNK1169 errors?
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.
Do you happen to have an earlier version that compiles without having to use "/FORCE"?
Do you happen to have an earlier version that compiles without having to use "/FORCE"?
-
- Posts: 115
- Joined: April 27th, 2012, 11:49 pm
Re: LNK 2005 and LNK1169 errors?
Do you mind posting the errors here?
Re: LNK 2005 and LNK1169 errors?
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.
Then actually define the variables in a .cpp file.
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;
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.
There are 10 types of people that understand binary.
Those that do, and those that don't.
Re: LNK 2005 and LNK1169 errors?
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 . And thank you everyone else.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.
Then actually define the variables in a .cpp file.Code: Select all
extern int nKills; extern int nEscapes; extern float scoreRatio;
Code: Select all
#include "Global.h" int nKills; int nEscapes; float scoreRatio;
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
Re: LNK 2005 and LNK1169 errors?
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.
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.
There are 10 types of people that understand binary.
Those that do, and those that don't.
Re: LNK 2005 and LNK1169 errors?
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.
Re: LNK 2005 and LNK1169 errors?
Sorry scratch that, i cant run anybodys game that uses chilies framework. So I have no idea why it works.