3

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!

Alex B
  • 1,438
  • 13
  • 17

3 Answers3

4

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.
Alex B
  • 1,438
  • 13
  • 17
  • 6
    “Unlike OS X development, you need a "makefile"” Not exactly. You need to link against the proper libraries. Using the pre-installed Makefile templates is simply an easy way to do that. The same goes for the Xcode project templates on Mac OS X. – Peter Hosey Sep 15 '09 at 23:17
  • I'm curious then how to link to the libraries - I searched the gcc and gnustep documentation up and down and did not find what I was looking for (which may in fact be my problem - I'm not even sure I know what I'm looking for). My app compiles fine in OS X using only the -framework option, but this is not available in Windows. – Alex B Sep 16 '09 at 13:37
  • The answer will be within the GNUstep-supplied Makefiles. – Peter Hosey Sep 16 '09 at 20:26
3

That's a linker error. #import is a preprocessor directive; it won't solve an error in linking, and you wouldn't have gotten as far as linking if you'd had a preprocessor error, anyway.

You need to link against Foundation and AppKit (especially the latter, for NSApplication), or whatever GNUstep's equivalents are.

Peter Hosey
  • 95,783
  • 15
  • 211
  • 370
0

Under Linux, you can compile with gcc :

gcc ``gnustep-config --objc-flags --gui-libs`` -o main main.m -L /usr/include/GNUstep/ -lobjc -lgnustep-base -lgnustep-gui

Owuzan
  • 21
  • 2