[Linker error] undefined reference to `camera'

I've been stuck on this for ages, so I'd really appreciate any insight into the problem.

I tried to add a camera class to the game I'm currently working on, but when I try to compile I juts get this error messages:
In function `ZN6Sprite4blitEP11SDL_Surface':
[Linker error] undefined reference to `camera'
[Linker error] undefined reference to `camera'

Here is the sprite class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//sprite.cpp

#include "SDL/SDL.h"
#include "sprite.h"
#include "image.h"
#include "camera.h"
#include "globals.h"
#include <string> 
using namespace std;

void Sprite::blit (SDL_Surface* setDest) {
    blit_image(camera.getXOffset(x), camera.getYOffset(y), image, setDest);
}

/*Some other sprite functions as well, but none of them reference "camera" */


Here is the globals file, where camera is declared:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//globals.h

#ifndef GLOBALS_H
#define GLOBALS_H

#include "camera.h"
#include "window.h"
#include "creature.h"
#include "sprite.h"
#include "player.h"
#include "tile.h"
#include "SDL/SDL.h"
#include "timer.h"
#include <string>
using namespace std;

const int FPS = 20; 
const int GRAVITY = 7;

extern int screenW;
extern int screenH;

extern Camera camera;
extern SDL_Surface *sky;
extern SDL_Surface *overlay;
extern Tile map [];
extern Tile bgMap [];  
extern Creature mobList;
extern Window mainWindow;
extern Creature yeti;
extern SDL_Event event;

#endif 


In main.cpp, the camera is defined as:
 
    Camera camera (0, 0);


This is camera.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef CAMERA_H
#define CAMERA_H

class Camera {
    private:
    int worldW;
    int worldH;
    int posX;
    int posY;
    public:
    int getXOffset (int);
    int getYOffset (int);    
    Camera (int, int);
};

#endif 


And here is camera.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "camera.h"

Camera::Camera (int getWorldW, int getWorldH) {
    worldW = getWorldW;
    worldH = getWorldH;
    posX = 0;
    posY = 0;
}

int Camera::getXOffset (int oldX) {
    int newX = oldX-posX;
    return newX;
}

int Camera::getYOffset (int oldY) {
    int newY = oldY-posY;
    return newY;
}


Sorry is that's a lot of code to sift through.
Any ideas, anybody?
one possibility: in main.o, camera is not defined in global scope - are you sure it's outside of main() body and outside of any other function's body?

post your main.cpp, if you're still having problems
Last edited on
Ahh, that works now.
Thanks very much, that's caused me so much grief!
np - as I have mentioned before, C++ shadowing is evil
Topic archived. No new replies allowed.