2011-08-02 68 views
10

我试图用Xcode制作一个简单的Mac Objective-C应用程序,以保持两位玩家玩一个简单游戏的分数,每位玩家最多可获得36分。由于其功能有限,它不是一个非常实用的应用程序,而且主要是用于练习。我试图用一个首选项窗口来扩展应用程序,当点击一个菜单项时会弹出​​。Command/Developer/usr/bin/clang失败,退出代码为1

我创建了一个文件来控制男性项目,然后点击时弹出一个笔尖。所有这些工作都很好,并且会弹出一个新窗口。我将滑块,文本字段等放在笔尖上,并将它们连接到动作。所有这一切都很好。

当我试图将文件导入到根控制器,以便我可以在应用程序中使用用户的选择时出现问题。

我得到以下编译器错误:

Command /Developer/usr/bin/clang failed with exit code 1 

伴随着这一切:

Ld "/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug/SimpleScoreKeeper Mac.app/Contents/MacOS/SimpleScoreKeeper Mac" normal x86_64 cd "/Users/myusername/Dropbox/iphone app/SimpleScoreKeeper Mac" setenv MACOSX_DEPLOYMENT_TARGET 10.6 /Developer/usr/bin/clang -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug -F/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug -filelist "/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper Mac.build/Debug/SimpleScoreKeeper Mac.build/Objects-normal/x86_64/SimpleScoreKeeper Mac.LinkFileList" -mmacosx-version-min=10.6 -framework Cocoa -o "/Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Products/Debug/SimpleScoreKeeper Mac.app/Contents/MacOS/SimpleScoreKeeper Mac"

ld: duplicate symbol _addScores in /Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper Mac.build/Debug/SimpleScoreKeeper Mac.build/Objects-normal/x86_64/Prefrences.o and /Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper Mac.build/Debug/SimpleScoreKeeper Mac.build/Objects-normal/x86_64/RootController.o for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Command /Developer/usr/bin/clang failed with exit code 1

(可能)相关的文件在我的项目如下。

RootController.h - All the interface declarations for stuff in the MainMenu.xib window 
RootController.m - Where I need to import the files to 
MainMenu.xib - The nib owned by the RootController class 
Preferences.h - A file I'd want to import, but it won't work. 
Preferences.m - A file I'd (maybe) want to import, but it won't work. 
Preferences.xib - The nib owned by the Preferences class. 
PreferencesMenuController.h - Where I declare the clickPreferences action. (Liked to MainMenu.xib) 
PreferencesMenuController.m - Where I say that clickPreferences opens up Preferences nib. (Linked to MainMenu.xib) 

有没有理由为什么我会得到这个错误?在我正在导入的课程中,我需要做些什么?请相当详细,我是新来的语言somight不知道如何做某些事情。如果有什么我需要澄清,让我知道。编号: 这是我无法导入的文件的代码

#import "Preferences.h" 

@implementation Preferences 

int addScores; 

- (IBAction)addScoresToggled 
{ 
    NSLog(@"addScores was toggled."); 
} 


- (id)initWithWindow:(NSWindow *)window 
{ 
    self = [super initWithWindow:window]; 
    if (self) { 

    } 

    return self; 
} 

- (void)dealloc 
{ 
    [super dealloc]; 
} 

- (void)windowDidLoad 
{ 
    [super windowDidLoad]; 
} 

@end 

回答

17

你也可以得到这个错误,你不小心包含了实现文件而不是头文件。例如#进口“MyClass.m”代替#进口“MyClass.h”

9

就是这个原因ld: duplicate symbol _addScore

在你的项目,你有_addScore文件超过一次。检查你的项目层次。

+0

我没有任何与下划线,究竟是什么意思?下面是我无法导入的.m文件的代码:编辑:由于注释中没有换行符,我还会在问题底部发布代码。 – ObjectiveProgrammer

+0

'#import“Preferences.h” @implementation Preferences int addScores; - (IBAction)addScoresToggled { NSLog(@“addScores was toggle。“); } - (ID)initWithWindow:(NSWindow *)窗口 { 自我= [超级initWithWindow:窗口]; 如果(个体){ } 返回自我; } - (空隙)的dealloc { [超级的dealloc];} - (无效)windowDidLoad { [超级windowDidLoad]; } @end ' – ObjectiveProgrammer

+1

可能晚了,但“int addScore”处于静态范围。所以,如果它包含在其他地方(或者在项目中多次包含文件),则最终会出现重复。 – GtotheB

0

我最近遇到这个错误。你是从两个不同的文件导入相同的.h文件吗?这对我造成了这个错误。

+0

本身不应该是个问题,听起来更像是你包含的头文件有问题(例如在头文件中实例化变量) – drfrogsplat

0

如果您希望变量addScore是在多个文件中accessable,你需要在一个.m文件将其定义为:

int addScore; 

,并在相关的.h文件声明它:

extern int addScore; 

如果离开了在声明中“外部”关键字,则编译器看到,作为addScore的每一个重新定义文件中的.h进口/包括进去。这会导致你看到的错误。

3

在收到完全相同的错误后,我注意到我以某种方式在我的项目中得到了两个同名的.h文件。删除项目文件夹中的副本(不仅仅是删除参考)解决了我的问题。

+0

类似的事情。项目中有两个.h文件参考。所以我删除了一个引用。 – utsabiem

+0

得到同样的错误。搜索最后导入的文件后发现重复的项目。 –

0

运行具有相同应用程序标识符的两个项目后,我遇到了同样的问题。

移除(使用您的帐户名称替换<yourlogin>)后:

project.xcworkspace/xcuserdata/<yourlogin>.xcuserdatad/UserInterfaceState.xcuserstate

它开始在模拟器中运行,但仍无法在设备上,所以我关闭了所有打开的项目,创造了一个新的,复制文件在那里,最后它的工作!

0

我在使用RestKit时遇到了同样的错误。我选择了RestKit目标并清理/构建它。然后我选择了我的主要目标(我的应用程序)并清理/构建它。为我修复它。

0

我满足这种类型的错误,当我存档的Xcode 4.3和4.4, 下一个项目,并终于我结束了该错误与来自标准(64分之32位Intel)切换到64 bitIntel

2

我刚才遇到这个问题,因为我有意外地导入了.m文件而不是.h文件。

对于任何试图回答此问题的人:如果问题突然出现,请仔细考虑您最近添加了哪些#import行(或者更好,请在git中运行grep!)。

0

我有一个不同的原因:使用Xcode 4.4时,部署目标设置为10.4时,最小值为10.6。这解决了我。

1

select demo.xcodeproj,显示包内容,删除名为project.xcworkspace

0

文件,并在F xcuserdata我就遇到了这个错误,当我不小心点击产品 - >测试,而不是产品 - >运行。我通过点击产品 - >清理来清理项目,错误消失了。

0

复制或模糊页眉或实现文件

当有到要导入的文件的多个潜在路径可能发生这种情况。 例如,如果您导入MyClass.h,但也有MyClass.h两个实例在您的项目

0

我的解决方案:

我已导入在我的项目的一些的.h和.m文件。但没有用过我的任何课程。 所以我删除了发现者。这导致了上述错误。

所以我不得不去项目设置/构建阶段=>然后也删除这些文件引用。他们是红色的。因为他们已经从发现者中删除而不是从Xcode

相关问题