collect2: ld returned 1 exit status error in Xcode
Im getting the error
Command /Developer/usr/bin/gcc-4.2 failed with exit code 1
and when the full log is opened, the error is more accurately listed as:
collect2: ld returned 1 exit status
from this simple Cocoa script:
#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
the .h file is this:
//
// Controller.h
//
//
#import <Cocoa/Cocoa.h>
@interface Controller : NSObject
开发者_如何学编程{
int skillcheck;
int contestcheck;
}
@end
and no line was specified that the error came from, does anyone know what the source of this error is, and more importantly, how to fix it?
EDIT:
I removed the class so now I have this:
//
// Controller.m
//
//
#import "Controller.h"
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);
}
and for the .h file:
//
// Controller.h
//
//
#import <Cocoa/Cocoa.h>
and the log says: (thanks to the guy who said how to open it)
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
If you want to declare skillcheck (which is not required in your case), then it's:
int skillcheck (int level, int modifer, int difficulty);
and not just:
int skillcheck;
which would define an int variable and not a function returning it. The same is true for contestcheck.
I propose you first read somewhat more about Objective-C to get the basics of the language.
Update:
It also seems that you have two definitions of main(), one in Controller.m and one main.m. You can only have one.
It isn't at all clear what you are trying to do. In that example, there is no need for an Objective-C class at all; it is just a main() function calling a C function and there is no Objective-C involved at all.
From the language of your question and the way that code is written, I'd guess that you are new to Cocoa programming. You might want to (re)read this.
There should be more information barfed up by the compiler/linker. Make sure you have "all messages" selected in the Build window.
精彩评论