【问题标题】:Command /Developer/usr/bin/clang failed with exit code 1命令 /Developer/usr/bin/clang 失败,退出代码为 1
【发布时间】:2011-10-17 22:31:19
【问题描述】:

我试图用 Xcode 制作一个简单的 Mac Objective-C 应用程序,以记录两名玩简单游戏的玩家的得分,每个玩家最多 36 分。由于功能有限,它不是一个非常实用的应用程序,并且主要用于练习。我试图使用首选项窗口稍微扩展应用程序,单击菜单项时会弹出​​该窗口。

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

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

我收到以下编译器错误:

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" 正常 x86_64 cd "/用户/我的用户名/Dropbox/iphone 应用程序/SimpleScoreKeeper Mac" setenv MACOSX_DEPLOYMENT_TARGET 10.6 /开发者/usr/bin/clang -arch x86_64 -isysroot /开发者/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 -文件列表 "/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:重复符号 _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 和 /Users/myusername/Library/Developer/Xcode/DerivedData/SimpleScoreKeeper_Mac-bjvjeiybvmwfjpfilvnpezarwkml/Build/Intermediates/SimpleScoreKeeper Mac.build/Debug/SimpleScoreKeeper Mac.build/Objects-normal/x86_64/RootController.o 用于架构 x86_64 clang:错误:链接器命令失败,退出代码为 1(使用 -v 到 请参阅调用)命令 /Developer/usr/bin/clang 失败并出现退出代码 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)

我收到此错误是否有原因?在我正在导入的课程中我需要做些什么吗?请非常详细,我是语言新手,可能不知道如何做某些事情。如果有什么需要澄清的,请告诉我。

编辑: 这是我无法导入的文件的代码。

#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

【问题讨论】:

    标签: objective-c xcode compiler-errors


    【解决方案1】:

    我的解决方案:

    我已经在我的项目中导入了一些 .h 和 .m 文件。但我的任何课程都没有使用它。 所以我从finder中删除了那些。这导致了上述错误。

    所以我必须进行项目设置/构建阶段 => 然后还要删除那些文件引用。他们是红色的。因为它们已从 finder 中删除,而不是从 Xcode 中删除

    【讨论】:

      【解决方案2】:

      DUPLICATE 或 AMBIGUOUS 头文件或实现文件

      当您要导入的文件有多个潜在路径时,可能会发生这种情况。 比如你导入了MyClass.h,但是你的项目中有两个MyClass.h的实例

      【讨论】:

        【解决方案3】:

        当我不小心单击产品 -> 测试而不是产品 -> 运行时,我遇到了这个错误。我刚刚通过单击 Product -> Clean 清理了项目,并且错误消失了。

        【讨论】:

          【解决方案4】:

          select demo.xcodeproj,显示包内容,删除名为project.xcworkspace的文件和f xcuserdata

          【讨论】:

            【解决方案5】:

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

            【讨论】:

              【解决方案6】:

              我刚才遇到了这个问题,因为我不小心导入了一个类的 .m 文件而不是 .h 文件。

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

              【讨论】:

                【解决方案7】:

                我在 Xcode 4.3 和 4.4 下归档项目时遇到这种错误, 最后我从标准(32/64位英特尔)切换到64位英特尔结束了这个错误

                【讨论】:

                  【解决方案8】:

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

                  【讨论】:

                    【解决方案9】:

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

                    删除后(将 替换为您的帐户名):

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

                    在模拟器下开始运行了,但设备上还是不行,所以我关闭了所有打开的项目,新建了一个并复制了文件,终于成功了!

                    【讨论】:

                      【解决方案10】:

                      在收到完全相同的错误后,我注意到我在项目中不知何故获得了两个同名的 .h 文件。从项目文件夹中删除重复项(不仅仅是删除引用)为我解决了这个问题。

                      【讨论】:

                      • 类似的事情。我在项目中有两个 .h 文件引用。所以我删除了一个参考。
                      • 得到同样的错误。搜索最后导入的文件后发现重复项。
                      【解决方案11】:

                      如果您希望变量 addScore 可以在多个文件中访问,则需要在一个 .m 文件中将其定义为:

                      int addScore;
                      

                      并在关联的 .h 文件中将其声明为:

                      extern int addScore;
                      

                      如果在声明中省略了“extern”关键字,那么编译器会将 .h 导入/包含到的每个文件中的 addScore 视为重新定义。这会导致您看到的错误。

                      【讨论】:

                        【解决方案12】:

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

                        【讨论】:

                          【解决方案13】:

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

                          【讨论】:

                          • 这本身不应该是一个问题,听起来更像是你包含的头文件有问题(例如在头文件中实例化变量)
                          【解决方案14】:

                          这就是ld: duplicate symbol _addScore的原因

                          在您的项目中,您的 _addScore 文件不止一次。检查您的项目层次结构。

                          【讨论】:

                          • 我没有下划线,这到底是什么意思?以下是我无法导入的 .m 文件的代码:编辑:由于 cmets 中没有换行符,因此我还将在问题底部发布代码。
                          • #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
                          • 可能晚了,但“int addScore”在静态范围内。因此,如果它包含在其他地方(或项目中多次包含的文件),您最终会得到一个副本。
                          猜你喜欢
                          • 1970-01-01
                          • 1970-01-01
                          • 1970-01-01
                          • 2012-05-09
                          • 1970-01-01
                          • 1970-01-01
                          • 1970-01-01
                          • 1970-01-01
                          • 2011-12-16
                          相关资源
                          最近更新 更多