Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c collect2:ld在Xcode中返回了1个退出状态错误_Objective C_Cocoa_Xcode - Fatal编程技术网

Objective c collect2:ld在Xcode中返回了1个退出状态错误

Objective c collect2:ld在Xcode中返回了1个退出状态错误,objective-c,cocoa,xcode,Objective C,Cocoa,Xcode,我得到了错误 Command /Developer/usr/bin/gcc-4.2 failed with exit code 1 打开完整日志时,错误更准确地列出如下: collect2: ld returned 1 exit status 从这个简单的Cocoa脚本: #import "Controller.h" @implementation Controller int skillcheck (int level, int modifer, int diffi

我得到了错误

Command /Developer/usr/bin/gcc-4.2 failed with exit code 1
打开完整日志时,错误更准确地列出如下:

collect2: ld returned 1 exit status
从这个简单的Cocoa脚本:

#import "Controller.h"

@implementation Controller

int skillcheck (int level, int modifer, int difficulty)
{
    if (level + modifer >= difficulty)
    {
        return 1;
    }
    if (level + modifer <= difficulty)
    {
        return 0;
    }
    
}

int main ()
{
    skillcheck(10, 2, 10);
}
    
@end

根本不清楚你想做什么。在这个例子中,根本不需要Objective-C类;它只是一个调用C函数的main()函数,根本不涉及Objective-C

从问题的语言和代码的编写方式来看,我猜您对Cocoa编程是新手。你可能想

编译器/链接器应该提供更多信息。确保在“生成”窗口中选择了“所有消息”。

如果要声明skillcheck(在您的情况下不需要),则:

int skillcheck (int level, int modifer, int difficulty);
不仅仅是:

int skillcheck;
它将定义一个int变量,而不是一个返回它的函数。这同样适用于竞争检查

我建议您首先阅读更多关于Objective-C的内容,以了解该语言的基础知识

更新:


似乎还有main()的两个定义,一个在Controller.m中,另一个在main.m中。您只能有一个。

Controller.m是否在当前目标中?“更准确”?不是真的-我们能看到更多的日志吗?如果你打开构建结果,在错误的右边应该是一个小按钮,看起来像许多行文本。单击它,它将显示导致失败的全文。这就是我们需要帮助的地方。是的,Controller.m在我的目标中,我在另一个线程上看到了这一点,并在前面检查过。是的,我是Cocoa编程新手,虽然不是一般编程,但我甚至不知道该脚本中有一个类,它在哪里?请阅读链接文档。然后回答问题“interface line做什么?”它生成了一个类,我现在已经删除了这个类好吧,多亏了你,我修复了这个错误,但是现在我得到了原始错误,现在完整的错误消息是什么?“Command/Developer/usr/bin/gcc-4.2失败,退出代码为1”和“collect2:ld返回1退出状态”只是其中的一小部分。请参阅我的更新。
//
//  Controller.h
//
//

#import <Cocoa/Cocoa.h>
Ld build/Debug/Calculator.app/Contents/MacOS/Calculator normal x86_64
cd /Users/anon/Desktop/Calculator
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/gcc-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/anon/Desktop/Calculator/build/Debug -F/Users/anon/Desktop/Calculator/build/Debug -filelist /Users/anon/Desktop/Calculator/build/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/Calculator.LinkFileList -mmacosx-version-min=10.6 -framework Cocoa -o /Users/anon/Desktop/Calculator/build/Debug/Calculator.app/Contents/MacOS/Calculator

ld: duplicate symbol _main in /Users/anon/Desktop/Calculator/build/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/Controller.o and /Users/anon/Desktop/Calculator/build/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/main.o
collect2: ld returned 1 exit status
Command /Developer/usr/bin/gcc-4.2 failed with exit code 1

ld: duplicate symbol _main in /Users/anon/Desktop/Calculator/build/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/Controller.o and /Users/anon/Desktop/Calculator/build/Calculator.build/Debug/Calculator.build/Objects-normal/x86_64/main.o


Command /Developer/usr/bin/gcc-4.2 failed with exit code 1
int skillcheck (int level, int modifer, int difficulty);
int skillcheck;