Install the object C development environment in windows and the hello word

Source: Internet
Author: User

I want to learn about iPhone Development recently, but because I don't have C basics, I only have Java basics. Therefore, we should first start with basic learning, and first build the environment. Currently, there is no mac host on hand. We can only learn basic syntax in windows. Fortunately, we found the gnuset, which can be used to simulate the object C development environment in windows.

Official Website: http://www.gnustep.org/

Installation:

Gnustep Windows Installer provides a simulated development environment for objective-C on the Windows platform. There are four software packages, including gnustep system.
And gnustep Core
Is required, gnustep devel
And Cairo backend
Is optional. Render manager must be installed and installed at one time, so as to avoid future troubles.

Compile helloword

Almost all development environments start with helloword. Here we write helloword first.

After the installation is complete, execute shell in the gnustep option in the Start menu to open the command line. Here, you can use VI to compile the object-C program, however, operations are always complicated. In fact, you can directly go to the C:/gnustep/home/username directory in windows. Here, you can use your favorite tools to compile the object-C program, then compile the program in shell.
The content of the helloworld. M file is provided directly, which is taken from programming in objective-C 2.0:

# 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;
}

 

First compilation:

Gcc-O helloworld. m

The error message is displayed. the header file cannot be found:

Helloworld. M: 1: 34: Foundation/Foundation. h: no such file or directory
Helloworld. M: In function 'main ':
Helloworld. M: 4: Error: 'nonutoreleasepool 'undeclared (first use in this function)
Helloworld. M: 4: Error: (each undeclared identifier is reported only once
Helloworld. M: 4: Error: for each function it appears in .)
Helloworld. M: 4: Error: 'pool 'undeclared (first use in this function)
Helloworld. M: 5: Error: cannot find interface declaration for 'nsconstantstring'



Second compilation:

Gcc-O helloworld. M/
-I/gnustep/system/library/headers/

The result shows an error message. The interface declaration cannot be found:

 

Helloworld. M: In function 'main ':
Helloworld. M: 5: Error: cannot find interface declaration for 'nsconstantstring'

Third compilation:

Gcc-O helloworld. M/
-Fconstant-string-class = nsconstantstring/
-I/gnustep/system/library/headers/

The result shows an error message. The Link Library cannot be found:

 

Helloworld. m :(. Text + 0 × 33): Undefined reference to '_ objc_get_class'
Helloworld. m :(. Text + 0 × 45): Undefined reference to '_ objc_msg_lookup'
Helloworld. m :(. Text + 0 × 64): Undefined reference to '_ objc_msg_lookup'
Helloworld. m :(. Text + 0 × 80): Undefined reference to '_ nslog'
Helloworld. m :(. Text + 0 × 93): Undefined reference to '_ objc_msg_lookup'
Helloworld. m :(. Text + 0xbc): Undefined reference to '___ objc_exec_class'
Helloworld. m :(. Data + 0 × 74): Undefined reference to '___ objc_class_name_nsautoreleasepool'
Helloworld. m :(. Data + 0 × 78): Undefined reference to '___ objc_class_name_nsconstantstring'
Collect2: LD returned 1 exit status

 

Fourth compilation:

Gcc-O helloworld. M/
-Fconstant-string-class = nsconstantstring/
-I/gnustep/system/library/headers //
-L/gnustep/system/library/libraries //
-Lobjc/
-Lgnustep-Base

Note: helloworld. m must appear before-lobjc and-lgnustep-base; otherwise, an error occurs.
At this time, some info prompts will appear, but it doesn't get in the way. Finally, an executable file is generated and the execution result is displayed.

 

./Helloworld.exe

The result is:

Note: You can use the copy and paste command: Ctrl + P

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.