Ok, so here I finally get to this point in my life that I can write pretty much syntax error free code, so I'm like, ‘that’s cool, now I can do anything’ well, just as things were looking up, here comes Link errors, to wreck my party. So long story short, I'm writing a 2D battle tank game, (the one were you aim, set bullet force, etc. sorta like worms) in C++ using SDL. Anyway, I'm on VC++ 6 and my code is in 4 parts:
Helper.cpp
Pixelwar.cpp
Terrain.cpp
Pixelwar.h
I’ll give you the includes/declarations of the files:
helper.cpp
#include "sdl.h"
#include <iostream>
#include <memory.h>
Pixelwar.cpp
#include "sdl.h"
#include <iostream>
#include <ctime>
#include <cmath>
#include <windows.h>
#include "pixelwar.h"
#include "helper.cpp"
#include "terrain.cpp"
// Functions
int init();
int frame();
//Variables
SDL_Surface* screen;
SDL_Event event;
Uint8* keys;
SDL_Color k;
cTerrain terrain;
terrain.cpp
#include "sdl.h"
#include <iostream>
#include <cmath>
#include "pixelwar.h"
class cTerrain {
public:
void InitTerrain(SDL_Color k);
void PixelOn(int x, int y);
void PixelOff(int x, int y);
void SetColor(SDL_Color k);
SDL_Color GetColor();
void draw(SDL_Surface* screen);
private:
bool PixArray[SCREEN_WIDTH][SCREEN_HEIGHT];
SDL_Color drawcolor;
};
void cTerrain::InitTerrain(SDL_Color k) {
int highY = 0;
for (int x = 0; x < SCREEN_WIDTH; x++) {
highY = ((rand() % SCREEN_HEIGHT) * -1) + SCREEN_HEIGHT;
for (int y = SCREEN_HEIGHT; y > 0; y--){
if (y > highY) PixArray[x][y] = true;
else PixArray[x][y] = false;
}
}
drawcolor = k;
}
pixelwar.h (whole file)
#include "sdl.h"
#include <iostream>
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define SCREEN_BPP 32
#ifndef _pixelwar_h_
#define _pixelwar_h_ 1
void SetPixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b);
SDL_Color GetPixel ( SDL_Surface* pSurface , int x , int y );
SDL_Color SDL_MakeColor (int r, int g, int b);
#endif
ok, so thats the files, heres the errors
--------------------Configuration: pixelwar - Win32 Debug--------------------
Compiling...
pixelwar.cpp
Linking...
pixelwar.obj : error LNK2005: "void __cdecl SetPixel(struct SDL_Surface *,int,int,unsigned char,unsigned char,unsigned char)" (?SetPixel@@YAXPAUSDL_Surface@@HHEEE@Z) already defined in helper.obj
pixelwar.obj : error LNK2005: "struct SDL_Color __cdecl GetPixel(struct SDL_Surface *,int,int)" (?GetPixel@@YA?AUSDL_Color@@PAUSDL_Surface@@HH@Z) already defined in helper.obj
pixelwar.obj : error LNK2005: "struct SDL_Color __cdecl SDL_MakeColor(int,int,int)" (?SDL_MakeColor@@YA?AUSDL_Color@@HHH@Z) already defined in helper.obj
terrain.obj : error LNK2005: "public: void __thiscall cTerrain::InitTerrain(struct SDL_Color)" (?InitTerrain@cTerrain@@QAEXUSDL_Color@@@Z) already defined in pixelwar.obj
terrain.obj : error LNK2005: "public: void __thiscall cTerrain::PixelOn(int,int)" (?PixelOn@cTerrain@@QAEXHH@Z) already defined in pixelwar.obj
terrain.obj : error LNK2005: "public: void __thiscall cTerrain::PixelOff(int,int)" (?PixelOff@cTerrain@@QAEXHH@Z) already defined in pixelwar.obj
terrain.obj : error LNK2005: "public: void __thiscall cTerrain::SetColor(struct SDL_Color)" (?SetColor@cTerrain@@QAEXUSDL_Color@@@Z) already defined in pixelwar.obj
terrain.obj : error LNK2005: "public: struct SDL_Color __thiscall cTerrain::GetColor(void)" (?GetColor@cTerrain@@QAE?AUSDL_Color@@XZ) already defined in pixelwar.obj
terrain.obj : error LNK2005: "public: void __thiscall cTerrain::draw(struct SDL_Surface *)" (?draw@cTerrain@@QAEXPAUSDL_Surface@@@Z) already defined in pixelwar.obj
MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/pixelwar.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Creating browse info file...
pixelwar.exe - 10 error(s), 1 warning(s)
mmmmk, im sorry all the stuff, but im confused, ive read some stuff about splitting files apart etc. but this one has me stumped
thanks in advance
-- Jake