If you have a Windows box handy, then you just need gcc with Objective-C support. The easiest way to do that in Windows is with MinGW, Minimalist GNU for Windows. The download page should have an Automated MinGW Installer for Windows.
Once you've installed MinGW, you can add the binaries to your path or use a build file of sorts; there are lots of options depending on your taste.
Let's see a basic Hello World app; we'll call it Main.m (m is the preferred file extension for Objective-C programs):
// From http://codewandering.blogspot.com/Look familiar? Objective-C is a proper superset of the C language, so valid C code is valid Objective-C code. Of course, to get the full power of Objective-C you'll want to use the object-oriented programming aspects of Objective-C as well.
// Main.m
int main(void)
{
printf("Hello, world!\n");
}
A simple batch file like this will compile the program:
@rem From http://codewandering.blogspot.com/You may need to modify the set path command if you specified a different home folder for MinGW.
setlocal
set path=%path%;c:\MinGW\bin\
gcc.exe -x objective-c Main.m -lobjc
endlocal
Now just run the batch file from a command line, which produces a.exe, your executable program. If you run that, you should see:
Hello, world!Ready for more? Check out these great resources:
- http://www.otierney.net/objective-c.html
- http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html
- http://www.stanford.edu/class/cs193p/cgi-bin/index.php
- http://courses.csail.mit.edu/iphonedev/
- Effort to create a cross-platform runtime environment similar to Cocoa (development must still be done on a Mac): http://www.cocotron.org/
4 comments:
this tutorial sucks. doesn't even mention how to use the foundation framework.
Feedback is welcome, but please keep it constructive.
I might agree with the analysis by Anonymous if this were a tutorial or purported to be one, or if the information was wrong when it was published. It is not, it does not, and it was not. It is merely a brief blog post. And 8 months old. Back when I wrote it, I was trying to do a little Objective-C on Windows. I researched on the web about how to set that up, but it was difficult to locate good information. I decided once I got everything figured out (which compiler was best, how to pass it the right arguments to build Objective-C, test that it actually worked...), in the spirit of cooperation, I might as well share it with others attempting the same. I also included links to further Objective-C and iPhone information, to help the reader once they got their compiler up and running.
8 months is an eternity in iPhone development. There may very well exist actual Windows Objective-C tutorials now in 2010. If anyone has a good one, please feel free to include a link here. Then we can all benefit.
If you just want to experiment, there's an Objective-C compiler for .NET (Windows) here: http://www.qckapp.com/index.html?p=ObjC
Mysteric , when i compile this, i was first force to write
#import
int main( int argc, const char *argv[] )
{
printf("Hello, world!\n");
return 0;
}
then it works, it produce an a.exe file.
When i try to execute, it complain about missing file:
libgcc_s_dw2-1.dll
what ??
It doesn't work.
I have install the latest gcc-objective-c what could possible be missing ?
Post a Comment