Use GNUstep to compile and run the OBJECTIVE-C program under Windows

Source: Internet
Author: User

This evening began to see the "Objective-c Program Design (4th edition)" This book (Oschina is doing this book review activities, see here for details), so far to see the 7th chapter, so want to try to write two simple program compiled run-and-run look.

Not accustomed to the MAC, under Windows installed a GNUstep can also play.

A very simple few steps, you also come to try it?

1. Download and install GNUstep

: http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/

There are three files that must be installed, respectively:

    • Gnustep-devel-1.4.0-setup.exe
    • Gnustep-core-0.31.0-setup.exe
    • Gnustep-msys-system-0.30.0-setup.exe

Here i download is the latest version, by default, the above three programs are installed in the same directory, I use the D:\GNUstep directory.

When the installation is complete, open: Start menu, All Programs, GNUstep, Shell will enter a Linux-like shell environment, as shown in:

You can do your own simple Linux commands, such as LS, mkdir, and so on.

Next we go to the/home directory and create a APP1 subdirectory:

?
123 cd/homemkdir app1cdapp1
This App1 directory is located in the D:\GNUstep\msys\1.0\home\app1 directory on the disk.

Next we write a simple program:

?
12345678910 #import <Foundation/Foundation.h>int main (int argc, const char *argv[]) {    //@autoreleasepool {    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];    NSLog(@"Hello oschina");    [pool drain];    //}    return 0;}
Description: Because the GCC compiler for the GNUstep band does not support OBJECTIVE-C 2.0, @autoreleasepool This directive is not supported and I commented it out.

We then use the following command to compile the program:

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

Above this command except-o after the parameters you can change, the other must be written, otherwise it will be wrong.

Parameter description, if you are familiar with the Linux/unix C + + compiler, the above parameters should be very familiar with,-I represents the path of the header file lookup,-l represents the library file lookup path,-L indicates the need to link the library file. However,-fconstant-string-class=nsconstantstring may be unfamiliar with this parameter, which is mainly the class used to specify the constant string.

After compiling, a executable program named App1.exe is generated in the current directory.

Enter the./app1.exe command to execute the program and execute the result:

2012-11-21 22:04:46.911 app1[4780] Hello Oschina

It's so easy! As for the meaning of each line in the code, let's read it.

A little more complicated program app2,app2 contains three files, respectively:

MAIN.M:

?
1234567891011121314 #import "Calculate.h"int main(int argc, char *argv[]){    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];     Calculate *cal = [[Calculate alloc] init];    int v = 5;    int av = 10;    [cal setNum: v];    [cal add: av];    NSLog(@"%i + %i = %i\n", v, av, [cal num]);    [pool drain];    return 0;}
Calculate.h:?
123456789101112131415 //Calculate.h#import <Foundation/Foundation.h>@interface Calculate : NSObject{    @private int num;}-(int) num;-(void) setNum: (int) n;-(void) add: (int) n;@end
CALCULATE.M:?
1234567891011121314151617181920 #import "Calculate.h"@implementation Calculate-(int) num{    return num;}-(void) setNum: (int) n{    num = n;}-(void) add: (int) n{    num += n;}@end
The compilation method is the same as above, just need to add two. m files in:?
1 $ gcc-o app2 Main.m Calculate.m -I/GNUstep/System/Library/Headers -fconstant-string-class=NSConstantString -L/GNUstep/System/Library/Libraries-lobjc -lgnustep-base

Run Result: 2012-11-21 22:17:51.207 app2[3144] 5 + 10 = 15

The question now is: Is there a way to get GNUstep to support OBJECTIVE-C 2.0? Official online has described this problem, need to use the clang compiler, do not know how to fix!

Sweet potatoes
Posted 3 year ago
20 back/11391 reads Tags:GNUstep objective-c GCC
    • Report
    • | Share to
0 Collection (over) Show latest comments by default sort

Use GNUstep to compile and run the OBJECTIVE-C program under Windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.