I made a simple experiment, I wrote the following code in Xcode:
int main(int argc, char** argv)
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
NSApplication* app = [[NSApplication alloc] init];
NSWindow* window = [[NSWindow alloc]
initWithContentRect: NSMakeRect(0, 0, 640, 480)
styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask
backing: NSBackingStoreBuffered
defer: NO];
[window setTitle: @"New Window"];
[window center];
[window makeKeyAndOrderFront:nil];
[app run];
[pool release];
return 0;
}
It runs as expected, a new empty window out there, but if I compile it under terminal with command line:
$ g++ test.mm -framework Cocoa
$ ./a.out
It will breeze at [app run] without the window.
Am I doing wrong? Why it has different behaviors between Xcode and command line? Does somebody can tell me how I can achive the same behaviors in command line?
Thanks in advance.
Taking your code and compiling it works fine for me on a 10.7.2 machine… the window shows up (albeit behind my terminal window and does not appear as a running application).
If you’re looking to get your app to show up as a process running in the dock, it has to be properly packaged in a .app bundle. If you do the following:
and then run
cli.app/Contents/MacOS/clifrom the command line, your process will show up as a running application.