OC学习之错误汇总
1、
第二个oc程序.m:5:32: error: non-ASCII characters are not allowed outside of
literals and identifiers
NSLog(@"第二个oc程序");
^~
第二个oc程序.m:5:32: error: expected ';' after expression
NSLog(@"第二个oc程序");
^
;
2 errors generated.
原因:分号非英文状态
2、
第二个oc程序.m:4:5: warning: implicitly declaring library function 'NSLog'
with type 'void (id, ...)'
NSLog(@"第二个oc程序");
^
第二个oc程序.m:4:5: note: please include the header
<Foundation/NSObjCRuntime.h> or explicitly provide a declarationfor
'NSLog'
1 warning generated.
原因:没有导入NSLog()方法对应的头文件
3、
Undefined symbols for architecture x86_64:
"_NSLog", referencedfrom:
_main in 第二个oc程序.o
"___CFConstantStringClassReference", referenced from:
CFString in 第二个oc程序.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exitcode 1 (use -v to see invocation)
原因:链接的时候加上 -frameworkFoundation
4、
two.m:1:1: error: unknown type name 'import'
import "two.h"
^
two.m:1:8: error: expected identifier or '('
import "two.h"
^
2 errors generated.
原因:import前面需要加#
5、
第1个OC的类.m:3:12: warning: class 'Car' defined without specifying a base class[-Wobjc-root-class]
@interface Car
^
第1个OC的类.m:3:15: note: add a super class to fix this problem
@interface Car
^
第1个OC的类.m:15:10: warning: class method '+new' not found (return type defaults to'id')
[-Wobjc-method-access]
[Car new];
^~~
2 warnings generated.
原因:Car类没有继承NSObject类
6、
第1个OC的类.m:3:12: warning: class 'Car' defined without specifying a base class[-Wobjc-root-class]
@interface Car
^
第1个OC的类.m:3:15: note: add a super class to fix this problem
@interface Car
^
第1个OC的类.m:15:10: warning: class method '+new' not found (return type defaults to'id')
[-Wobjc-method-access]
[Car new];
^~~
2 warnings generated.
zhuwenchengdeMac-mini:test zhuwencheng$ cc -c 第1个OC的类.m
第1个OC的类.m:3:16: error: cannot find interface declaration for 'NSObejct',superclass of 'Car'; did
you mean 'NSObject'?
@interface Car:NSObejct
^~~~~~~~
NSObject
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/objc/NSObject.h:53:12:note:
'NSObject' declared here
@interface NSObject <NSObject> {
^
1 error generated.
原因:NSObject写错
7、
zhuwenchengdeMac-mini:test zhuwencheng$ cc -c 08-第2个OC的类.m
08-第2个OC的类.m:3:19: error: cannot find interface declaration for 'NSobject',superclass of
'Person'; did you mean'NSObject'?
@interface Person:NSobject
^~~~~~~~
NSObject
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/objc/NSObject.h:53:12:note:
'NSObject' declared here
@interface NSObject <NSObject> {
^
08-第2个OC的类.m:9:1: error: expected identifier
@end
^
08-第2个OC的类.m:8:15: error: expected ';' after method prototype
- (void) walk:
^
;
08-第2个OC的类.m:15:30: error: non-ASCII characters are not allowed outside of literalsand
identifiers
NSLog (@"走了一段路",age,weight);
^~
08-第2个OC的类.m:15:33: error: expected ')'
NSLog (@"走了一段路",age,weight);
^
08-第2个OC的类.m:15:11: note: to match this '('
NSLog (@"走了一段路",age,weight);
^
08-第2个OC的类.m:24:8: error: 'Person' does not have a member named 'age'
p->age = 20;
~ ^
08-第2个OC的类.m:25:8: error: 'Person' does not have a member named 'weight'
p->weight = 59;
~ ^
7 errors generated.
原因:NSObject写错成NSobject;- (void) walk;错写成- (void) walk:;
,age,weight错写成age,weight并且age,weigtht未定义。
8、
08-第2个OC的类.m:18:30: warning: data argument not used by format string[-Wformat-extra-args]
NSLog(@"走了一段路",age,weight);
~~~~~~~~~~~~~ ^
1 warning generated.
原因:age,weigth前面未接收,应输入%d,%f
9、
13-练习.m:12:1: error: missing context for method declaration
- (int) comareSpeedWithOther:(Car *)other;
原因:comareSpeedWithOther上下文中没有
本文汇总了OC编程中常见的错误,包括非ASCII字符、缺少分号、未导入头文件、链接错误、import语法错误、类定义错误、方法访问警告等问题,并详细解释了错误原因及解决方案。

1万+

被折叠的 条评论
为什么被折叠?



