Mickey Tin
Mickey Tin

Reputation: 3533

Error LNK 2005 Visual Studio 2008

Please help to build my project, i gave up after 2nd hour. That is how it looks like: Solution Explorer

BrickClass.h

 - #include"header.h"

header.h

 - #pragma once
 - #include windows.h
 - #include windowsX.h
 - #include tchar.h
 - #include commctrl.h
 - #include "matrixClass.h"
 - #include "resource.h"

mainClass.h

 - #include "header.h"
 - #include "brickClass.h"

matrixClass.h

 - #include cstdlib
 - #include cstdio
 - #include math.h

brickClass.cpp

 - #include "brickClass.h"

main.cpp

 - #include "mainClass.h"

mianClass.cpp

 - #include "mainClass.h"

the error

What i need to do to make him happy?I was tried a lot of variants but cant figure out HOW..? Appreciate your help. The project is Here : http://www.filehosting.org/file/details/381812/Tetris.rar

Upvotes: 0

Views: 354

Answers (1)

paxdiablo
paxdiablo

Reputation: 881093

If you're giving up after the 2nd hour, this probably isn't the right industry for you :-) There'll be times when you'll have spent days trying to solve a problem, kicking yourself at the end because it was so simple in retrospect.


Anyway, on to the problem at hand. It's almost certainly because you have code in your BrickClass header file.

By including that header file in both main.cpp (via mainClass.h) and BrickClass.cpp, each of the object files gets an independent copy of the code.

Then, when you try to link those object files together, the linker finds that there are two copies.

Header files should generally contain declarations, like extern int i; or function prototypes such as int xyzzy (void);.

The definitions, like int i; and functions such as int xyzzy (void) {return 42;}, should only be placed in the "regular" source files.

Upvotes: 2

Related Questions