I'm having trouble with some code. I'm writing some O.O. code in C++ and Objective C (Using the .mm file format) and when I try to compile, it creates a linking error where it detects duplicate symbols. The code I'm about to show is of the Controller.h and Controller.mm files, and it's a class of a shape that will be made. I don't want to include this in the main file because I need to know how to do make other class files, and I don't want lots and lots of classes cluttering up the main file.
It DOES HAVE external libraries being imported here, but don't get confused. None of the code inside the functions are relevant. Even without the code in them compiling still gives the same error. The error is by the way:
ld: duplicate symbol ControllerClass::makeController(b2World*) in /Users/Daniel/Documents/XCode/2dFirst/build/Debug-iphonesimulator/libcocos2d libraries.a(Controller.o) and /Users/Daniel/Documents/XCode/2dFirst/build/2dFirst.build/Debug-iphonesimulator/2dFirst.build/Objects-normal/i386/Controller.o
The code is:
Controller.h
#import "Box2D.h"
#import "cocos2d.h"
class ControllerClass {
b2PolygonShape dynamicBox;
b2BodyDef bodyDef;
b2FixtureDef fixtureDef;
public:
b2World* world;
b2Body* body;
b2Fixture* fixture;
CGPoint makeFloorPoint;
CGPoint makeControllerPoint;
void makeFloor(b2World* world);
void makeController(b2World* world);
};
Controller.mm
#define PTM_RATIO 32
#include "Controller.h"
void ControllerClass::makeFloor(b2World* world) {
makeFloorPoint = CGPointMake(160,0);
//Make the body
bodyDef.type = b2_kinematicBody;
//Position set
bodyDef.position.Set(makeFloorPoint.x/PTM_RATIO, makeFloorPoint.y/PTM_RATIO);
body = world->CreateBody(&bodyDef);
//Make a polygon shape
dynamicBox.SetAsBox(5.0f, 0.1f);
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 0.3f;
fixtureDef.friction = 0.3f;
fixtureDef.isSensor = true;
fixture = body->CreateFixture(&fixtureDef);
}
void ControllerClass::makeController(b2World* world) {
makeControllerPoint = CGPointMake(140, 160);
//Make the body
bodyDef.type = b2_dynamicBody;
//Position set
bodyDef.position.Set(makeControllerPoint.x/PTM_RATIO, makeControllerPoint.y/PTM_RATIO);
body = world->CreateBody(&bodyDef);
//Make a polygon shape
dynamicBox.SetAsBox(.75f, .75f);
//Fixture defenition and creation
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 0.3f;
fixtureDef.friction = 0.3f;
fixtureDef.isSensor = true;
body->CreateFixture(&fixtureDef);
}
This code is of HelloWorld.h (Yet to be Renamed
#import "cocos2d.h"
#import "Box2D.h"
#import "GLES-Render.h"
#import "Controller.h"
// HelloWorld Layer
@interface b2Science : CCLayer {
b2World* world;
GLESDebugDraw *m_debugDraw;
b2MouseJoint *_mouseJoint;
b2Body* groundBody;
ControllerClass controller;
}
// returns a Scene that contains the HelloWorld as the only child
+(id) scene;
// adds a new sprite at a given coordinate
-(void) addNewSpriteWithCoords:(CGPoint)p;
@end
Please no suggestions on optimisation or speed of the code, just on the problem at hand. I will get to the other stuff later, I just want it to work for now.

New Topic/Question
Reply
MultiQuote







|