» about » content » twitter » github »

Compiling Objective-C on Windows

I'll ignore the "why" for a moment (if you want to develop for iOS, you need a Mac), but I needed to have some small command-line Objective-C programs compile and run on both OSX and Windows, so I did the following:

From http://www.gnustep.org/experience/Windows.html download and install the following packages:

GNUstep MSYS System
GNUstep Core
GNUstep Devel

Once installed, open the GNUStep shell and test by typing:

gcc -v

If that works, in your home directory (something like C:\GNUstep\msys\1.0\home\yourname), create a file called hello.m with the following content:

// objective-c test for windows compile

int main (int argc, const char * argv[])
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSLog (@"hello world");
        [pool drain];
        return 0;

Then compile it as follows:

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

If you see the results as hello world then you've been successful.

© Roqet 2019 :: 2019-01-04 14:18:13