Macos Cocoa/OSX环境上的运行时错误

Macos Cocoa/OSX环境上的运行时错误,macos,cocoa,Macos,Cocoa,我只是想在VirtualBox上的MacOSX(SnowLeopard 10.6.3)上使用Cocoa快速包装OpenGL设置。我只使用了一个带有嵌入式OBJ C的.cpp文件 我的(相关)代码如下: #include <stdio.h> #ifdef __APPLE__ #include <unistd.h> 'usleep' // OpenGL #include <OpenGL/OpenGL.h> #includ

我只是想在VirtualBox上的MacOSX(SnowLeopard 10.6.3)上使用
Cocoa
快速包装OpenGL设置。我只使用了一个带有嵌入式OBJ C的
.cpp
文件

我的(相关)代码如下:

#include <stdio.h>

#ifdef __APPLE__
   #include <unistd.h>          'usleep'
   // OpenGL
   #include <OpenGL/OpenGL.h>
   #include <OpenGL/gl.h>
   #include <OpenGL/glu.h>
   // Cocoa
   #import <Cocoa/Cocoa.h>

   ... some interfaces in OBJ-C
#endif

int main() {

...

#ifdef __APPLE__

   bool run_mainloop = true;

      // the main OpenGL loop
      while(run_mainloop) {
         NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

         // Cocoa event loop
         while(1) {
            [pool release];
            pool = [[NSAutoreleasePool alloc] init];

            NSEvent *event;
            event = [NSApp
              nextEventMatchingMasK: NSAnyEventMask
              untilDate: NSDefaultRunLoopMode
              dequeue:YES
            ];

            ...

            [pool release];
         }
      }

#endif
编译结果没有错误,但有以下警告:

main.cpp: In function ‘int main()’:
main.cpp:188: warning: no ‘-nextEventMatchingMasK:untilDate:dequeue:’ method found
main.cpp:188: warning: (Messages without a matching method signature
main.cpp:188: warning: will be assumed to return ‘id’ and accept
main.cpp:188: warning: ‘...’ as arguments.)
当我尝试运行二进制文件时:

./macbin.out
我收到一个
未捕获的异常
错误:

2014-10-13 13:05:46.362 macbin.out[476:903] -[NSApplication    nextEventMatchingMasK:untilDate:dequeue:]: unrecognized selector sent to instance   0x100118190
2014-10-13 13:05:46.367 macbin.out[476:903] An uncaught exception was raised
2014-10-13 13:05:46.369 macbin.out[476:903] -[NSApplication nextEventMatchingMasK:untilDate:dequeue:]: unrecognized selector sent to instance 0x100118190
2014-10-13 13:05:46.372 macbin.out[476:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication nextEventMatchingMasK:untilDate:dequeue:]: unrecognized selector sent to instance     0x100118190'...
有人能解释一下吗?如何设置下一个显然是错误的
nexteventmachmask
?Thanx

您有一个打字错误

nextEventMatchingMasK:
应该是:

nextEventMatchingMask:
您可能已经习惯了一个不同的环境,在这个环境中类似的东西是无法编译的。Objective-C会将许多注意事项推到运行时,但是,编译器可能应该警告您未知的选择器

看起来该消息可能有更多错误:

- (NSEvent *)nextEventMatchingMask:(NSUInteger)mask untilDate:(NSDate *)expiration inMode:(NSString *)mode dequeue:(BOOL)flag
尝试传递inMode:的NSDefaultRunLoopMode,而不是untilDate:

event = [NSApp
          nextEventMatchingMask: NSAnyEventMask
          untilDate: [NSDate distantPast]
          inMode: NSDefaultRunLoopMode
          dequeue:YES
        ];

thanx为catch:)但我仍然无法找到该方法。。不知道为什么我把
inMode
untilDate
混合在一起。Thanx。Thanx的答案是,是的,我主要是一个Windows和一点linux的程序员,所以Obj-C对我来说只是一个丛林:)Thanx的细节
event = [NSApp
          nextEventMatchingMask: NSAnyEventMask
          untilDate: [NSDate distantPast]
          inMode: NSDefaultRunLoopMode
          dequeue:YES
        ];