2012-05-06 38 views
2

锵和gcc有一个选项可以禁止发送未定义消息给对象的警告吗?如果是这样,那么旗帜是什么?Clang和gcc选项可抑制未定义的消息警告?

随着铛3.1:

test.mm:51:14: warning: instance method '-dfs_path:' not found (return type defaults to 'id') 
      ([pathfinder dfs_path: graph, @[ NUM(start) ], NUM(goal), NUM(max_steps)]) 
      ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

用gcc 4.2.1:

test.mm: In function ‘void test_path(objc_object*, objc_object*, int, int, int, BOOL)’: 
test.mm:84: warning: no ‘-dfs_path:’ method found 
test.mm:84: warning: (Messages without a matching method signature 
test.mm:84: warning: will be assumed to return ‘id’ and accept 
test.mm:84: warning: ‘...’ as arguments.) 
test.mm:84: warning: no ‘-dfs_path:’ method found 

基本上,在MacRuby的产生有问题的方法,因此,目标C编译器不知道他们在编译时。

+0

你得到的* exact *警告是什么? –

+0

@KenThomases:我编辑了这个问题来澄清。 – echristopherson

回答

2

Xcode中大部分来自clang的警告都会提供有关在警告消息本身中处理特定警告的信息。如果手动运行铛(或以其他方式没有看到这些),还有以铿锵,一个选项开启此行为:

-f[no-]diagnostics-show-option 

如果使用-fdiagnostics-show-option作为一个编译器选项,那么你应该看到列出的选项在警告,如:

foo.m:73:1: warning: category is implementing a method which will also be implemented by its 
      primary class [-Wobjc-protocol-method-implementation] 

这表明-Wobjc-protocol-method-implementation选项导致错误,并添加-Wno-objc-protocol-method-implementation一般将其禁用。因此,我建议不要关闭未定义方法的警告,方法定义将影响编译器如何处理返回值,并且可能会在稍后为您带来许多麻烦。

如果您没有合适的包含文件,则可以始终使用类别为该方法声明本地定义。不是最干净的方式(这将包括声明),但有时是必要的。

@interface class_you_are_having_issues_with() 
- (id)dfs_path: (id)unknownarg, ... 
@end 

顺便说一句,我假定这是一个可变参数的方法,因为这是关于你用逗号分隔的ARGS在Objective-C的唯一一次。

希望这会指出你在两条正确的方向。

+0

感谢您的回答,但使用-fdiagnostics-show-option没有给我更多的指示来抑制警告。我想我只是试图让Obj-C做一些它没有设计的东西 - 在使用静态和动态语言之后,我想看看使用Obj-C作为一种动态语言是什么样的(为了目前的目的,这意味着将对象声明为id并可自由调用动态定义的方法)。这只是一个智力练习。 – echristopherson

+0

我想现在我可以考虑这个“回答”,即使答案不是我所希望的。 – echristopherson

0

尝试-Wno-objc-method-access - 在叮当中为我工作。