Objective-c – How to compile a GNUstep application that uses NSApplication on Windows

cocoagccgnustepobjective cwindows

I am exploring with compiling an application with GNUstep on Windows. This is my main.m file:

#import <???/???.h>

int main(int argc, const char *argv[]) 
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [NSApplication sharedApplication];
    [pool release];
}

I realize this is an incomplete fragment to say the least and it obviously won't do anything. I have tried several different import statements including Cocoa/Cocoa.h, GNUstepGUI/GMAppKit.h, etc. But I always run into errors with compiling that I can't seem to find help with online.

This is my compile command, which I am running from the mingw shell:

gcc -o test main.m -I /GNUstep/System/Library/Headers/ \
    -L /GNUstep/System/Library/Libraries/ -lobjc -lgnustep-base \
    -fconstant-string-class=NSConstantString -enable-auto-import

These are the errors I get:

c:/WINDOWS/TEMP/ccHxKZG2.o:main.m(.data+0x390): undefined reference to
  '___objc_class_name_NSApplication'
collect2:ld returned 1 exit status

Any ideas on what I need to #import, or what needs fixing in my compile command?

Thanks!

Best Answer

Thanks to Peter Hosey I was able to Google myself to the page with the answer:

http://psurobotics.org/wiki/index.php?title=Objective-C

Unlike OS X development, you need a "makefile":

Put this into a file called "GNUmakefile" in the same directory as your source:

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = MyAppName
MyAppName_HEADERS =
MyAppName_OBJC_FILES = main.m
MyAppName_RESOURCE_FILES =

include $(GNUSTEP_MAKEFILES)/application.make

Then execute

make

The page says to execute

openapp ./MyAppName.app
but the .exe file within the .app folder appears to run on its own.