Michaelzanussi.com header image

Compiling Objective-C Programs in Windows

This post was derived from an article on compiling Objective-C programs in Windows using gcc under GNUstep. That great article also provides details on compiling in Linux and Mac OS X (outside Xcode).

1) Download and install GNUstep System and GNUstep Core. I used 0.24.2 stable release of GNUstep to compile these notes but they may work under newer versions.

2) Run msys.bat which, if you installed GNUstep with the defaults, will be located in C:\GNUstep.

3) Change to home directory (/home/username) containing your Objective-C source.

4) Create the hello.m source.

/******************* hello.m ***********************/
#import <Foundation/Foundation.h>

@interface HelloWorld : NSObject
 - (void) hello;
@end

@implementation HelloWorld
- (void) hello {
  NSLog(@"hello world!");
}
@end

int main(void) {
  HelloWorld *hw = [[HelloWorld alloc] init];
  [hw hello];
  [hw release];
}

/******************* end ***********************/

5) Compile the application.

gcc `gnustep-config --objc-flags` -o hello hello.m -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base

If that doesn’t work try:

gcc -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString

or

gcc `gnustep-config --objc-flags` -o hello hello.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -enable-auto-import

All three of these commands worked fine for me.

6) Run ./hello

7) Optionally, you can compile using make. To do so create a GNUmakefile in your home directory where your Objective-C files are located.

include $(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = hello
hello_OBJC_FILES = hello.m
include $(GNUSTEP_MAKEFILES)/tool.make

Now run make.

Run ./hello which will be in the obj directory under your home directory.

0 Comments on “Compiling Objective-C Programs in Windows”

Leave a Comment

You must be logged in to post a comment.