Build an objective-C learning environment in Windows

Source: Internet
Author: User

Nowadays, iPhone development is getting increasingly popular, and I am also eager to learn about objective-C. However, the company is a clear Windows XP system (not a sound picture of the company's machine) (^_^) and cannot learn and debug it. One of the most taboo ways to learn programming languages is to read a book rather than do it. Therefore, you must try writing several programs in a simulated environment. I heard that there is a simulated Unix environment with gnustep on the Internet, so I downloaded one online.

 

In: http://www.gnustep.org/experience/Windows.html

Four installation packages are required: gnustep System

, Gnustep Core

, Gnustep devel

, Cairo backend

The installation in sequence is OK.

 

On Windows, there can be no objective-C development environment like xcode on Mac OS X, so you need to find a simple and convenient editing environment.

General examples include ultraedit, notepad ++, and emeditor. I have always used emeditor for my personal habits.

 

Compile an example program to test whether the environment is correct. Recently, I am reading objective-C beginner's guide.pdf, so I wrote the example about the nsdictionary class again.

First, go to the user directory under the gnustep installation directory. If the user name of the current system is Chen and the gnustep is installed on drive C, the home directory of the current user should be

C:/gnustep/home/Chen.

 

Then open the Start menu and start the console program of the gnustep shell just installed.

Run the Unix Command mkdir dictionary to create the directory Dictionary of the example program, and run the CD dictionary command to enter the directory.

Create two files in this directory. One is the source code file dictionary. m and the other is the compilation configuration file gnumakefile.

 

The test code dictionary. m is as follows:

# Import <Foundation/nsstring. h> <br/> # import <Foundation/NSAID utoreleasepool. h> <br/> # import <Foundation/nsdictionary. h> <br/> # import <Foundation/nsenumerator. h> <br/> # import <Foundation/Foundation. h> <br/> # import <stdio. h> <br/> void print (nsdictionary * map) {<br/> nsenumerator * enumerator = [map keyenumerator]; <br/> ID key; </P> <p> while (Key = [enumerator nextobject]) {<br/> printf ("% s => % s/n ", <br/> [[Key description] cstring], <br/> [[[map objectforkey: Key] description] cstring]); <br/>}< br/> int main (INT argc, const char * argv []) {<br/> nutoreleasepool * Pool = [[nutoreleasepool alloc] init]; <br/> nsdictionary * dictionary = [[nsdictionary alloc] initwithobjectsandkeys: <br/> @ "one", [nsnumber numberwithint: 1], <br/> @ "two", [nsnumber numberwithint: 2], <br/> @ "three", [nsnumber numberwithint: 3], nil]; <br/> nsmutabledictionary * mutable = [[nsmutabledictionary alloc] init]; </P> <p> // print dictionary <br/> printf ("---- static dictionary/N"); <br/> Print (dictionary ); </P> <p> // Add objects <br/> [mutable setobject: @ "Tom" forkey: @ "tom@jones.com"]; <br/> [mutable setobject: @ "Bob" forkey: @ "bob@dole.com"]; </P> <p> // print mutable dictionary <br/> printf ("---- mutable dictionary/N "); <br/> Print (mutable); </P> <p> // free memory <br/> [dictionary release]; <br/> [mutable release]; <br/> [pool release]; </P> <p> return 0; <br/>}

 

Compile the configuration file gnumakefile as follows:

Include $ (gnustep_makefiles)/common. Make <br/> tool_name = dictionary <br/> dictionary_objc_files = dictionary. m <br/> include $ (gnustep_makefiles)/tool. Make

 

After editing and saving the file, return to the shell environment and enter the make command to compile the source code. The compiler will automatically find the gnumakefile configuration file in the current directory.

If the compilation is successful, an OBJ directory is automatically generated, which contains the target file after the compilation link.

Run the./obj/dictionary.execommand to start the generated dictionary.exe file and observe the running result.

 

This is the process of building the encoding and compilation. You need to add the gnumakefile compiling file.

In this example, the order of the four rows of configuration statements cannot be messy, but there can be empty rows in the middle,

Tool_name = dictionary

Dictionary

_ Objc_files = dictionary. m

The red letter indicates the final generated target name, that is, the executable file name can be different from the source code file name.

The source code is not explained. It is purely typed. After reading the entire document, the 34-page document looks very easy.

 

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.