我只是想在 VirtualBox 的Cocoa
上使用Mac OSX (snow leopard 10.6.3)
来快速打包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
编译代码的命令如下(我在 gcc 中使用):
g++ -x objective-c++ -framework Cocoa -framework OpenGL main.cpp -o macbin.out
编译结果没有错误但有警告:
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
我收到uncaught exception
错误:
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'...
有人可以解释一下吗?如何设置显然是错误的nextEventMatchMask
? Thanx
答案 0 :(得分:0)
你有一个错字
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
];