在Windows上使用GNUstep和Objective-C

In addition to using Objective-C on a Mac system, it is also possible to download and install the GNUstep and Objective-C environments for Microsoft's Windows family of operating systems. In this chapter we will explore the steps involved in downloading, installing and testing both Objective-C and GNUstep on Windows.

Contents

[hide]
Downloading the GNUstep Packages

The GNUstep environment is made available on Windows using a toolkit called MinGW. MinGW is an abbreviation ofMinimal GNU for Windows and essentially provides a port of the GNU compiler collection, including Objective-C support, and a minimal shell environment for Windows platforms. Installation of GNUstep involves installing both MinGW and GNUstep. Both of these packages are available from the GNUstep web site at http://www.gnustep.org/experience/Windows.html.

The MinGW package is contained in the GNUstep System download and the GNUstep core is contained, unsurprisingly, in theGNUstep Core download. Both must be downloaded before proceeding with the installation.

[edit]Installing MinGW and GNUstep on Windows

Once the required packages have been downloaded, locate the GNUstep System file and launch it to initiate the installation process. To complete the installation, simply follow the prompts in the installation wizard, using the default installation settings unless you have specific requirements. In particular, should you decide to install the package in a location other than C:\GNUstep, you will need to adjust the instructions in the remainder of this chapter accordingly.

<style type="text/css"> <!-- --> </style>

Installing Objective-C on Windows


Once MinGW is installed, repeat the process for the GNUstep Core package.

[edit]Running the GNUstep Shell

To begin using Objective-C and GNUstep, start the GNUstep shell by selecting Start -> All Programs -> GNUstep -> Shell. Once loaded, the shell will appear as follows:

<style type="text/css"> <!-- --> </style>

The GNUstep shell running on Windows

[edit]Testing the Installation

The shell environment is a minimalist version of the shell environment you might find on a Linux or Unix system. If you are unfamiliar with such an environment then it is unlikely you will want to perform the code editing in this window. Fortunately, it is still possible to use your favorite editor on Windows.

When the shell is first started, it places you in the home directory for the GNUstep/MinGW environment. In terms of the Windows file system, and assuming you used the default installation location for MinGW and GNUstep, this is equates to:

C:\GNUstep\home\<username>

Where <username> is the name by which you logged into the Windows system. To create a simple application, open a suitable editor (Notepad will do) and enter the following code:

#import <Foundation/Foundation.h>

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

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

Once the code has been entered, save the file in your GNUstep home directory (as outlined above) ashello.m. If you used Notepad, be sure to switch the Save as Type option toAll Files so that the file is not given a .txt file name extension.

Once the code has been written and saved, it can be compiled from the GNUstep shell window by entering the following command:

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

Assuming a successful compilation, run the application as follows:

./hello.exe

When executed, the test program should produce output similar to:

2009-09-24 14:31:25.721 hello[2200] hello world
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值