`

Objective C programming in Windows – GNUStep & ProjectCenter

    博客分类:
  • iOS
 
阅读更多

http://www.jaysonjc.com/programming/objective-c-programming-in-windows-gnustep-projectcenter.html

 

I have been toying with the idea of getting into full fledged iPhone application development for sometime now. To get into iPhone development, you need to be familiar with Objective C language and Cocoa framework. But the iPhone development environment is only available for Mac platform (which includes Xcode IDE and iPhone simulator). If you want to run iPhone development environment without a Mac machine, you have two options,

  • Use a virtual machine platform like VMWare to run OSX under Windows – However it is not legal to run OSX under non Apple hardware.
  • Another option is to use OSx86 which allows you to install Mac OS on top of your Intel or AMD computer.

But if you just want to learn Objective C language or Cocoa framework programming, you don’t need any of the above. You just need the GNUStep and ProjectCenter tools. This article explains how GNUStep can be configured as a Objective C development environment on Windows.

Objective C Programming in Windows using GNUStep

GNUStep is a free, object oriented development environment with built in tools such as a compiler. The C/C++ compiler included (gcc) also supports compiling Objective C programs. It also has a graphical development kit with API similar to Cocoa framework (since both of them were derived from the old OpenStep framework). So installing GNUStep on Windows gives an instant development environment for Objective C programs. An extension to GNUStep is the ProjectCenter (Xcode equivalent) using which graphical programs can be built.

Installing GNUStep on Windows

GNUStep is available as a Windows installer from the official page .  I recommend downloading and installing GNUStep System, GNUStep Core and GNUStep Devel. Note that the latest version available as of October 2009 is 0.23.0 and this version is not compatible with ProjectCenter 0.50 .  If you are planning to use ProjectCenter I recommend that you download 0.22.0 version of GNUStep from the download page . Here is a summary of what is required,

  • Objective C programming only – GNUStep 0.23 (System | Core | Devel )
  • Objective C Programming and ProjectCenter 0.50 -  GNUStep 0.22 (System | Core | Devel )

You can download pre-compiled version of ProjectCenter 0.50 for Windows from here .

image Once you install all the binaries above, you will have GNUStep shell under Programs->GNUStep (See figure). Click on the Shell to invoke the command line interface. This shell is based on MinGW (collection of gcc compiler and command line tools) and using it you can compile and run Objective C programs. The command line is similar to Unix/Linux command line and you can navigate to any folder in your windows machine. Using the built in gcc program you can compile and run Objective C programs.

Compiling and running Objective C programs in GNUStep on Windows

Create the following program and save it with the name helloworld.m using notepad,

#import <Foundation/Foundation.h> 
int main (int argc, const char * argv[])
{
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  NSLog (@"Hello World!");
  [pool drain];
  return 0;
}

 

Now using GNStep shell navigate to the folder where helloworld.m is stored (in my case it is cd w:/prg ). Type in the following command to compile helloworld.m.

gcc -o helloworld helloworld.m -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries -lobjc -lgnustep-base -fconstant-string-class=NSConstantString

 Please note that the various switch options such as -lobjc should appear at the end of the command. the -o switch specifies the name of the executable created (helloworld.exe) in this case. Following is the result of compilation,

Info: resolving ___objc_class_name_NSAutoreleasePool by linking to __imp____objc

_class_name_NSAutoreleasePool (auto-import)

Info: resolving ___objc_class_name_NSConstantString by linking to __imp____objc_

class_name_NSConstantString (auto-import)

W:\Tools\GNUstep\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.e

xe: warning: auto-importing has been activated without –enable-auto-import spec

ified on the command line.

This should work unless it involves constant data structures referencing symbols

from auto-imported DLLs.
 

You can see that helloworld.exe is generated in the same folder (Ignore compiler output and warnings or use -enable-auto-import switch to fix them). To run the program type in ./helloworld.exe at the command prompt,

image

Common Errors during Objective C compilation

  • error: cannot find interface declaration for `NXConstantString’ – This means that you haven’t added the switch -fconstant-string-class=NSConstantString to the gcc command line.
  • Foundation/Foundation.h: No such file or directory – This means that gcc is unable to find Foundation header classes. Use the switches -I /GNUstep/System/Library/Headers -L /GNUstep/System/Library/Libraries
  • stray ‘@’ in program – This means that you have the wrong double quote in your source code. Use " instead of .

Now you are all set for Objective C programming and a bit of Cocoa programming on Windows. Good luck! and buy a Mac machine when you are ready to write iPhone programs.

Further Reference

分享到:
评论

相关推荐

    Clang GNUstep Objective C for Windows

    可以使用GNUstep在Windows XP上寫Objective-C程式,但是Objective-C已經加了很多新東西,而GNUstep裡的gcc並不提供,所以,这个是GNUstep,再加上新一代的編譯器架構Clang與LLVM(這也是Apple在新版Xcode裡預設使用...

    ProjectCenter-0.6.1

    the gnustep-msys-system package

    windows 下搭建 Objective-C 开发环境

    总结来说,在Windows系统下搭建Objective-C开发环境虽然不像在Mac OS X上那样直接便捷,但通过使用GNUstep等工具,我们依然可以实现在Windows系统下的Objective-C开发。希望这份详细的指南能够帮助那些需要或希望在...

    CodeBlocks&GNUstep开发环境配置 Objective-C编译器

    CodeBlocks和GNUstep是两种广泛使用的开源开发工具,它们在Objective-C编程中扮演着重要的角色。Objective-C是一种面向对象的编程语言,它是苹果生态系统,包括iOS和macOS开发的基础。本篇文章将详细介绍如何配置和...

    Windows下配置Objective-C编译运行环境

    在Windows系统上配置Objective-C的编译运行环境可能比在Mac上更为复杂,因为Objective-C主要是为Apple的iOS和macOS平台设计的。不过,通过一些工具和步骤,你可以在Windows上搭建一个基本的环境来学习和实验...

    Windows下的Objective-C集成开发环境的搭建

    尽管它主要与苹果的Xcode IDE紧密关联,但在Windows环境下,我们同样可以通过配置其他工具来搭建Objective-C的开发环境。本文将详细介绍如何在Windows上使用Codeblocks作为IDE来搭建Objective-C的开发环境。 首先,...

    Windows7下编译运行Objective-C

    然而,描述中提到的GNUstep项目使得Objective-C的使用范围扩展到了非苹果平台,包括Windows操作系统。在这个场景下,我们关注的是如何在Windows 7环境下编译和运行Objective-C代码。 GNUstep是一个开源项目,它的...

    GNUstep安装文件part1

    6. **开发工具**:GNUstep提供了Gorm(GUI构建工具)和ProjectCenter(项目管理工具),帮助开发者设计用户界面和管理项目。这些工具可以帮助你快速创建和组织代码,以及可视化布局界面。 7. **社区支持**:GNUstep...

    windows平台搭建Objective-C环境

    在Windows平台上搭建Objective-C开发环境是一项相对复杂但可行的任务,主要依赖于GNUstep项目,它是一个开源实现的Objective-C环境,旨在提供与Apple的Mac OS X上的Cocoa类似的功能。以下是一个详细的步骤指南: 1....

    GNUStep入门教程(中文)

    - **编译工具**: GNUGCC 3.x版本开始支持Objective-C语言,GNUStep项目还提供了一个名为GNUstep Make的工具,简化了Objective-C程序的构建过程。GNUstep Make使用类似Makefile的语法,即GNUmakefile,使构建过程更加...

    GNUstep OC编译学习工具包

    GNUstep OC 编译学习工具包是一套专为Windows用户设计的编程工具,旨在帮助开发者在Windows环境下编译和学习Objective-C(OC)程序。Objective-C是苹果公司开发的面向对象编程语言,广泛用于iOS和macOS应用开发。...

    Windows XP 系统下创建 Objective-C 集成开发环境

    本文旨在详细介绍如何在 Windows XP 操作系统中搭建一套基于 GNUstep 和 CodeBlocks 的 Objective-C 集成开发环境(IDE)。该环境对于希望在 Windows 平台上进行 Objective-C 应用程序开发的开发者来说非常实用。 #...

    GNUstep part1

    GNUstep Objective C iPhone Apple GNUstep Objective C iPhone Apple GNUstep Objective C iPhone Apple

    windows 配置objective-c 开发环境 详细教程

    ### Windows配置Objective-C开发环境详细教程 #### 一、引言 随着移动互联网的发展,Objective-C作为iOS开发的重要语言之一,其应用范围虽然主要集中在Mac OS X和iOS平台,但有时候开发者可能需要在Windows平台上...

    Windows下进行Objective-c开发.docx

    然而,通过使用GNUstep,一个开源的Objective-C框架,开发者可以在Windows上构建和运行Objective-C代码。下面将详细介绍如何在Windows下设置Objective-C的开发环境,并编写并运行一个简单的“Hello, World!”程序。 ...

    Objective C 学习心得 (一):--Windows下搭建objective C开发环境.docx

    Objective C是一种由苹果公司推出的基于C语言的面向对象编程语言,主要用于开发iOS和macOS平台的应用程序。在本文中,我们将探讨如何在Windows环境下搭建Objective C的开发环境,这对于那些想学习Objective C但又...

    Objective-C基础教程(入门教程).pdf

    Objective-C是一种广泛用于苹果平台应用程序开发的编程语言,它是C语言的一个超集,并加入了Smalltalk风格的消息传递机制。本篇教程主要面向初学者,介绍了Objective-C的基础知识点和一些核心概念。 1. Objective-C...

    windows下Objective-C开发步骤

    在Windows环境下进行Objective-C开发可能不如在macOS上直观,但通过GNUStep提供的工具链,我们仍然可以实现跨平台的开发。熟悉这些工具和命令行操作对于提升开发效率至关重要。随着对Objective-C语法和GNUStep的理解...

    GNUstep安装包

    1. **Objective-C 语言**: Objective-C是C语言的超集,添加了Smalltalk式的消息传递机制,是Cocoa和GNUstep框架的基础。它支持面向对象编程,是开发Mac OS X和iOS应用的主要语言。在GNUstep中,Objective-C同样用于...

Global site tag (gtag.js) - Google Analytics