Next: 7 Debugging an Application Up: Writing GNUstep Makefiles Previous: 5 Disabling Debugging

6 A first App

Let's try now to compile an application. Modify our source file source.m to read
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

main (void)
  NSAutoreleasePool *pool;
  pool = [NSAutoreleasePool new];
  [NSApplication sharedApplication];
  NSRunAlertPanel (@"Test", @"Hello from the GNUstep AppKit", 
                   nil, nil, nil);

  return 0;
(Ignore the autorelease pool code for now - we'll cover autorelease pools in detail later). The line containing sharedApplication initializes the GNUstep GUI library; then, the following line runs an alert panel. To compile it, we rewrite the GNUmakefile as follows:
include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = PanelTest
PanelTest_OBJC_FILES = source.m

include $(GNUSTEP_MAKEFILES)/application.make
And that's it. To compile, type in make. The result is slightly different from a command line tool. When building an application, the application usually has a set of resources (images, text files, sound files, bundles, etc) which comes with the application. In the GNUstep framework, these resources are stored with the application executable in an 'application directory', named after the application, with app appended. In this case, after compilation the directory should have been created. Our executable file is inside this directory; but the correct way to run the executable is through the openapp tool, in the following way:
openapp ./
(openapp should be in your path; if it is not, you should check that GNUstep is properly installed on your system).