problems with headers!!!
for the first time i''m trying to program something with more that one cpp file and a header. It''s camera.cpp (which I didn''t forget to add to the project), main.cpp (main prog) and main.h, the file given below. MSVC++ 6.0 gives the following errors:
Linking...
main.obj : error LNK2005: "unsigned int WindHeight" (?WindHeight@@3IA) already defined in camera.obj
main.obj : error LNK2005: "class CCamera Camera" (?Camera@@3VCCamera@@A) already defined in camera.obj
main.obj : error LNK2005: "unsigned int WindWidth" (?WindWidth@@3IA) already defined in camera.obj
Debug/main.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.
Could someone tell me what''s wrong? Here''s the code for the header, thanx!
Marty
Code for the header file. (codes''s for class CCamera are in camera.cpp)
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "glaux.lib")
#include <math.h>
#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glut.h>
#include <gl\glaux.h>
typedef struct Vec3
{
Vec3(){}
Vec3(float x, float y, float z)
{X = x; Y = y; Z = z ;}
Vec3 operator + (Vec3 AddVector)
{return Vec3(AddVector.X+X, AddVector.Y+Y, AddVector.Z+Z);}
Vec3 operator - (Vec3 SubstractVector)
{return Vec3(X-SubstractVector.X, Y-SubstractVector.Y, Z-SubstractVector.Z);}
Vec3 operator * (float Scalar)
{return Vec3(X*Scalar, Y*Scalar, Z*Scalar);}
Vec3 operator / (float Scalar)
{return Vec3(X/Scalar, Y/Scalar, Z/Scalar);}
float X, Y, Z;
}Vec3;
/*void NormalizeVector(Vec3 &Vector)
{
float length = (float)(sqrt(Vector.X * Vector.X +
Vector.Y * Vector.Y +
Vector.Z * Vector.Z));
Vector.X = (float)(Vector.X / length);
Vector.Y = (float)(Vector.Y / length);
Vector.Z = (float)(Vector.Z / length);
}*/
class CCamera
{
public:
void Position( float pos_x, float pos_y, float pos_z,
float view_x, float view_y, float view_z,
float up_x, float up_y, float up_z);
void Move(float MoveCount);
void Rotate(float x, float y, float z);
void MouseLook();
void CameraView();
private:
Vec3 Pos, View, Up;
};
GLuint WindWidth, WindHeight = 500;
CCamera Camera;
_____ /____ /|| | || MtY | ||_____|/Marty
February 28, 2003 03:04 PM
you are double including same file...
#ifndef HEADER_NAME
#define HEADER_NAME
//header code comes here...
#endif
#ifndef HEADER_NAME
#define HEADER_NAME
//header code comes here...
#endif
Or write
#pragma once
at the beginning of each .h file...
PM
Times change.
Excuse my poor english!
#pragma once
at the beginning of each .h file...
PM
Times change.
Excuse my poor english!
PM Times change...
Excuse my poor english!
It''s generaly a VERY BAD idea to define variables in a header! Define them in a .cpp file.
quote:
Original post by VolkerG
It''s generaly a VERY BAD idea to define variables in a header! Define them in a .cpp file.
Yeah, that''s right...
2Marty666:
If u want the variables to be accesable in any file which includes your header, define them in a cpp file and write
extern vartype varname;
in a h file...
(vartype is the type of the variable and varname is the name of the variable, of course

BTW If u get an unresolved external error, your variables are declared as extern but they arent defined in a cpp file...
PM
Times change.
Excuse my poor english!
PM Times change...
Excuse my poor english!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement