Skip to main content
gamedev.net
🔒 Locked

linking error

Started by prince_of_persia 6 replies 750+ views
Original Post
prince_of_persia
prince_of_persia
hi i have a vc++ ssource code and i declare some var my project was worked but now have this error this error is for wath? --------------------Configuration: SkelAnimTut - Win32 Debug-------------------- Linking... Model.obj : error LNK2005: "int endframe" (?endframe@@3HA) already defined in MilkshapeModel.obj Model.obj : error LNK2005: "int startframe" (?startframe@@3HA) already defined in MilkshapeModel.obj Model.obj : error LNK2005: "double m_FPS" (?m_FPS@@3NA) already defined in MilkshapeModel.obj Model.obj : error LNK2005: "double m_totalFrames" (?m_totalFrames@@3NA) already defined in MilkshapeModel.obj NeHeCode.obj : error LNK2005: "int endframe" (?endframe@@3HA) already defined in MilkshapeModel.obj NeHeCode.obj : error LNK2005: "int startframe" (?startframe@@3HA) already defined in MilkshapeModel.obj NeHeCode.obj : error LNK2005: "double m_FPS" (?m_FPS@@3NA) already defined in MilkshapeModel.obj NeHeCode.obj : error LNK2005: "double m_totalFrames" (?m_totalFrames@@3NA) already defined in MilkshapeModel.obj Debug/SkelAnimTut.exe : fatal error LNK1169: one or more multiply defined symbols found Error executing link.exe. SkelAnimTut.exe - 9 error(s), 0 warning(s)
ToohrVyk
ToohrVyk
You defined the variable in several translation units. The usual reason for that is that the variable is defined in a header (some fool will probably suggest that you use header guards, but they're not relevant).

Global variables should be declared in a header file, preceded by the extern keyword:

extern type variable_name;

And then, defined in a single source file, perhaps being given a value:

type variable_name = value;

If you didn't intend for the variables to be global, post the code where they are defined.
prince_of_persia
prince_of_persia
here is the code:
//////////////////
/*
Model.h

Abstract base class for a model. The specific extended class will render the given model.

Author: Brett Porter
Email: brettporter@yahoo.com
Website: http://rsn.gamedev.net
Copyright (C)2001, Brett Porter. All Rights Reserved.

This file may be used only as long as this copyright notice remains intact.
*/

#ifndef MODEL_H
#define MODEL_H

#include "Matrix.h"
#include "Timer.h"
double m_FPS;
double m_totalFrames;
int startframe=1;
int endframe=1;
class Model
{
public:
// Mesh
struct Mesh
{
int m_materialIndex;
int m_numTriangles;
int *m_pTriangleIndices;
};

// Material properties
struct Material
{
float m_ambient[4], m_diffuse[4], m_specular[4], m_emissive[4];
float m_shininess;
GLuint m_texture;
char *m_pTextureFilename;
};

// Triangle structure
struct Triangle
{
float m_vertexNormals[3][3];
float m_s[3], m_t[3];
int m_vertexIndices[3];
};

// Vertex structure
struct Vertex
{
char m_boneID; // for skeletal animation
float m_location[3];
};

// { NEW }
// Animation keyframe information
struct Keyframe
{
int m_jointIndex;
float m_time; // in milliseconds
float m_parameter[3];
};

// Skeleton bone joint
struct Joint
{
float m_localRotation[3];
float m_localTranslation[3];
Matrix m_absolute, m_relative;

int m_numRotationKeyframes, m_numTranslationKeyframes;
Keyframe *m_pTranslationKeyframes;
Keyframe *m_pRotationKeyframes;

int m_currentTranslationKeyframe, m_currentRotationKeyframe;
Matrix m_final;

int m_parent;
};
// { end NEW }
///////////////////////


this is project link:
www.rasaonline.ir/walker.zip

this project will work good if press F5 an run it
but if select 'rebuild all' will be harmed and not work

thanks
ToohrVyk
ToohrVyk
double m_FPS;double m_totalFrames;int startframe=1;int endframe=1;


If you do not wish these variables to be global, you might want to group them into appropriate classes or structures. Otherwise, just use my above explanation.

gdunbar
gdunbar
Quote:
Original post by prince_of_persia
double m_FPS;
double m_totalFrames;
int startframe=1;
int endframe=1;


A quick fix would be to declare these variables static (like "static double m_FPS"), which means you can only use them in this source file, and thus eliminates the conflict (since they aren't globals anymore). Others have posted more elegant fixes which are probably a better long term idea.

Geoff
Kylotan
Kylotan
Quote:
Original post by gdunbar
Quote:
Original post by prince_of_persia
double m_FPS;
double m_totalFrames;
int startframe=1;
int endframe=1;


A quick fix would be to declare these variables static (like "static double m_FPS"), which means you can only use them in this source file, and thus eliminates the conflict (since they aren't globals anymore).


I doubt the poster really wants individual copies of those variables in each .cpp file, however.

prince_of_persia
prince_of_persia
no i declare static my vars but now i have this error

/*
MilkshapeModel.h

Loads and renders a Milkshape3D model.

Author: Brett Porter
Email: brettporter@yahoo.com
Website: http://rsn.gamedev.net
Copyright (C)2001, Brett Porter. All Rights Reserved.

This file may be used only as long as this copyright notice remains intact.
*/

#ifndef MILKSHAPEMODEL_H
#define MILKSHAPEMODEL_H

#include "Model.h"

static double m_FPS;
static double m_totalFrames;
static int startframe=1;
static int endframe=1;



class MilkshapeModel : public Model
{
public:
/* Constructor. */
MilkshapeModel();
////////////////////////////////error
--------------------Configuration: SkelAnimTut - Win32 Debug--------------------
Compiling...
Model.cpp
d:\new folder (2)\walker salem\walker salem\the press\model.cpp(262) : error C2065: 'startframe' : undeclared identifier
d:\new folder (2)\walker salem\walker salem\the press\model.cpp(262) : error C2065: 'm_FPS' : undeclared identifier
d:\new folder (2)\walker salem\walker salem\the press\model.cpp(264) : error C2065: 'endframe' : undeclared identifier
d:\new folder (2)\walker salem\walker salem\the press\model.cpp(264) : error C2065: 'm_totalFrames' : undeclared identifier
Error executing cl.exe.

SkelAnimTut.exe - 4 error(s), 0 warning(s)

Kylotan
Kylotan
Your globals should be marked as 'extern' in the header that declares them, and without the 'extern' in one single .cpp file.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.