Use GNU to develop objective-C in Windows

Source: Internet
Author: User

In addition to using objective-C on MAC systems, you can also download and install the gnustep and objective-C environments on Windows. What is gnustep and its usefulness, here is a brief introduction: gnustep provides APIs and tools similar to cocoa (Apple OS Development Framework). It currently supports GNU/Linux and GNU/Hurd, Solaris, NetBSD, OpenBSD, freeBSD, Darwin, and windows are free of charge. This project enables Objective C to be developed and run on most popular platforms. For more information, see the official website of gnustep.
Next we will introduce the detailed installation and use steps.

Download gnustep

In the gnustep environment, you can use the mingw tool in Windows. The mingw is a portable version of the GNU compilation tool in windows. Installing gnustep includes installing mingw and gnustep, both of which can be downloaded here: http://www.gnustep.org/experience/Windows.html.

Mingw includes gnustep system and gnustep core, which must be installed first.

Four major software packages: gnustep msys system, gnustep core, gnustep devel, and Cairo backend. The first two software packages must be installed. The third software package is to install some development tools, such as GCC and G ++. Therefore, if you are learning objective C, this package must also be installed. The fourth package is to install libraries such as glib. The installation of this package is not based on the actual situation.

Install mingw and gnustep

After downloading the required package, you can start installation. In the graphical Installation Wizard interface, we specify the installation directory as c: \ gnustep.

Once mingw is installed, you can install the gnustep core package.

Run gnustep Shell

To start using objective-C and gnustep, start the gnustep shell and run the shell from the gnustep in the Start Menu, as shown in:

Test after installation

This shell environment is a minimal version of Linux or Unix environment. If you are not familiar with this environment, you can also use the editor you are familiar with in windows.

Under "All Programs" in the "Start" menu, you can find "gnustep"-> "shell", and the console window is displayed. You can try some Linux commands (LS, CD, mkdir ).

Compile an Objective C code to compile and run the test. Here we use the classic "Hello World" to describe:
# Import <Foundation/Foundation. h>
Int main (INT argc, const char * argv []) {
NSAID utoreleasepool * Pool = [[NSAID utoreleasepool alloc] init];
Nslog (@ "Hello world! ");
[Pool drain];
Return 0;
}

In Windows, use a text editor (editplus, ue, etc.) to write the above Code and save itUnder the gnustep installation directory/Home, named helloworld. M.

(Note that if GNU is installed on drive C, it will be stored elsewhere, and Cd in shell will be OK, otherwise no such file or directory will always appear.) In the console window command line of gnustep,

1. CD/home

2. GCC-O helloworld. m-I/gnustep/system/library/headers-fconstant-string-class = nsconstantstring-L/gnustep/system/library/Libraries-lobjc-lgnustep-Base

3rd, run helloworld.exe

Note: If you are familiar with C/C ++ compilation in Linux/Unix, the above parameters should be familiar with.-I indicates the path for header file search, -l indicates the path for Searching database files, and-l indicates the library files to be linked. However,-fconstant-string-class = nsconstantstring may be unfamiliar with this parameter, which is mainly the class used to specify the constant string.

 

Improvement:Since the gnustep window cannot be copied, pasted, or typed manually, it is prone to errors. Therefore, you can write a shell script namedTest. Sh, The content is as follows:

Gcc-o "$1" "$2"-I/gnustep/system/library/headers-fconstant-string-class = nsconstantstring-L/gnustep/system/library/Libraries- lobjc-lgnustep-Base

Then, as shown above, run the command line in the console window of gnustep.

1. CD/home

2. Sh test. Sh helloworld. m

3rd, run helloworld.exe

Note: test. $1 and $2 in SH indicate obtaining and executing test. sh, and then use sh test. sh helloworld. M is to execute test. sh script and pass in two parameters. The purpose of passing parameters is to make this test. SH is a compilation template, so that you can compile and run different parameters each time.

If helloworld.exe is compiled and run successfully, it indicates that the objective C development environment has been set up in windows, so that you can start learning objective C in a cheap way.


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.