Objective-C has almost become Apple's patent. You can compile the Objective-C program directly on Apple's Xcode, but there are few compilation tools on the Windows platform, not many people use this language. Today, I suddenly saw a post posted on the Internet. I can compile Objective-C on the Windows platform and tried it with curiosity. I didn't expect it to succeed. Now I will share with you my experience on how to build the Objective-C compiling platform.
1. Install GNUstep
GNUstep Windows Installer provides a simulated development environment for Object-C on the Windows platform. There are a total of four software packages, including GNUstep System and GNUstep Core, GNUstep Devel and Cairo Backend are optional. Only the first two installation methods are enough.
2. compile Objective-C code
After the installation is complete, run shell in the GNUstep option in the Start menu to open the command line. Directly go to the C:/GNUstep/home/Administrator directory in Windows (my Administrator may be different, here, you can use your favorite tools (now the UltraEdit and Notepad ++ editor seem to be able to highlight Code) to compile the Object-C program.
For example: HelloWorld. m
1
# Import <Foundation/Foundation. h>
2
3
Int main (int argc, const char * argv []) {
4
NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init];
5
NSLog (@ "Hello World! ");
6
[Pool drain];
7
8
Return 0;
9
}
3. Configure Environment Variables
This step is important. GNUstep. sh is used to set the GNUstep development environment variables. If it is not executed, there will be many header files, library files, and commands cannot be found.
After the source code is written in a directory, compile a make configuration file named GNUmakefile. The content is
1
Include $ (GNUSTEP_MAKEFILES)/common. make
2
TOOL_NAME = Test
3
Test_OBJC_FILES = HelloWorld. m
4
Include $ (GNUSTEP_MAKEFILES)/tool. make
You can modify the simhei section above.
Then
1
Make
After the command is run successfully, an obj directory is added, which contains the executable files and. o files you want.
OK.
Summary: how to compile Objective-C on Windows is complete. I hope this article will help you!
1. Download GNUStep
Http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/
Download
Gnustep-msys-system-x.x.x-setup.exe
Gnustep-core-x.x.x-setup.exe
Gnustep-cairo-x.x.x-setup.exe
Gnustep-devel-x.x.x-setup.exe
Install the downloaded GNUStep, such as C: \ GNUStep.
2. Download JEdit
Http://www.jedit.org/index.php? Page = download
JEdit is Freeware and can be used to edit the. m file. m is the default Suffix of Object C. . M is equivalent to the. c file.
3. An Object C textbook
Http://www.otierney.net/objective-c.html
---------------
4. After installation, run msys. bat to start the GNUStep environment (similar to the Linux environment)
5. Compile the sample program
Fraction. h
# Import <Foundation/NSObject. h>
@ Interface Fraction: NSObject {
Int numerator;
Int denominator;
}
-(Void) print;
-(Void) setNumerator: (int) n;
-(Void) setDenominator: (int) d;
-(Int) numerator;
-(Int) denominator;
@ End
Fraction. m
# Import "fraction. h"
# Import
@ Implementation Fraction
-(Void) print {
Printf ("% I/% I", numerator, denominator );
}
-(Void) setNumerator: (int) n {
Numerator = n;
}
-(Void) setDenominator: (int) d {
Denominator = d;
}
-(Int) denominator {
Return denominator;
}
-(Int) numerator {
Return numerator;
}
@ End
Main. m
# Import
# Import "fraction. h"
Int main (int argc, const char * argv []) {
// Create a new instance
Fraction * frac = [[Fraction alloc] init];
// Set the values
[Frac setNumerator: 1];
[Frac setDenominator: 3];
// Print it
Printf ("The fraction is :");
[Frac print];
Printf ("\ n ");
// Free memory
[Frac release];
Return 0;
}
6. Write Makefile
Create GNUmakefile in the current directory
Include $ (GNUSTEP_MAKEFILES)/common. make
TOOL_NAME = Hello
Hello_OBJC_FILES = main. m fraction. m
Include $ (GNUSTEP_MAKEFILES)/tool. make
6. Compile the program
$ Make
Run hello.exe to create the obj directory.
The fraction is: 1/3
In this way, the environment is ready, and you can continue to learn Object C.
Mac OS is generally used to write iphone programs.
Author: xiahuawuyu