重复的符号

时间:2012-09-09 14:09:20

标签: objective-c symbols

仍在努力完成我的游戏,并且每次遇到困难我都会玩#34; gameSpeed"这取决于所选择的困难。

但是,在尝试运行我的应用程序时,我收到以下错误:

duplicate symbol _gameSpeed in:
/Users/Ashley/Library/Developer/Xcode/DerivedData/Whack-etfeadnxmmtdkgdoyvgumsuaapsz/Build/Intermediates/Whack.build/Debug-iphonesimulator/Whack.build/Objects-normal/i386/TimedGameLayer.o
/Users/Ashley/Library/Developer/Xcode/DerivedData/Whack-etfeadnxmmtdkgdoyvgumsuaapsz/Build/Intermediates/Whack.build/Debug-iphonesimulator/Whack.build/Objects-normal/i386/GameInfo.o
ld: 1 duplicate symbols for architecture i386
collect2: ld returned 1 exit status
Command /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1

我只在一个地方使用gameSpeed。

在这里:

[self schedule:@selector(tryPopMoles:) interval:gameSpeed];

这是我的TimedGameLayer.m

gameSpeed var在我的GameInfo.h中

我像这样导入标题:

#import "GameInfo.h"

我的GameInfo.h看起来像这样:

@interface GameInfo : NSObject
+(void)setupGame:(enum GameType)type withArg2:(enum GameDifficulty)difficulty;
+(void)resetGame;
+(void)togglePause;

@end

//Game Type
enum GameType gameType;
enum GameDifficulty gameDifficulty;

//Release Version
NSString *version;

//Settings
int gameSpeed = 1.5;

//Stats
int touches = 0;
int score = 0;
int totalSpawns = 0;

//usables
bool gamePaused = FALSE;

typedef enum GameType {
    GameTypeClassic = 0,
    GameTypeUnlimited,
    GameTypeTimed,
    GameTypeExpert,
} GameType;

typedef enum GameDifficulty
{
    GameDifficultyEasy = 0,
    GameDifficultyMedium,
    GameDifficultyHard,
} GameDifficulty;

我的setupGame函数(位于我的GameInfo.m文件中)如下所示:

+(void)setupGame:(enum GameType)type withArg2:(enum GameDifficulty)difficulty
{
    gameType = type;
    gameDifficulty = difficulty;

    switch(gameDifficulty)
    {
        case GameDifficultyEasy:
            gameSpeed = 1.5;
            break;
        case GameDifficultyMedium:
            gameSpeed = 1.0;
            break;
        case GameDifficultyHard:
            gameSpeed = 0.5;
            break;
    }
}

我完全迷失在这里......

有什么想法吗?

由于

1 个答案:

答案 0 :(得分:1)

根据您的评论和示例代码:

您在.h文件中声明了一系列变量,并且多次包含.h文件,因此您有多个具有相同名称的变量。您应该创建一个constants.h和constants.m文件,并在常量文件中将该列表声明为常量。

constants.h:
extern const int gameSpeed;

constants.m:
const int gameSpeed = 1;

顺便说一下,你将gameSpeed声明为一个int,但是给它赋一个浮点值,所以gameSpeed将等于1.改用float类型。