2009. 12. 15. 07:33

Objective C programming in Windows - GNUStep & ProjectCenter

Windows 에서 Objective C 를 빌드하고 실행할 수 있는 환경을 구축해 보자. (iPhone 개발 환경이 아니다.)

GNUStep 설치하기

GNUStep 은 아래 공식 페이지에서 다운로드 가능한다. GNUStep System, GNUStep Core 그리고 GNUStep Devel 을 설치할 것을 추천한다.

http://www.gnu.org/software/gnustep/experience/Windows.html

윈도우즈용 ProjectCenter 0.50 은 아래 링크에서 다운받을 수 있다.

http://ftp.gnustep.org/pub/gnustep/binaries/windows/

설치를 완료하였다면 Programs>GNUStep 하위에 GNUSTep Shell 이 있을 것이다. 커맨드 라인 인터페이스를 실행하기 위해 Shell 을 클릭하라. 이 셀은 MinGW 에 기초하였으며 이것을 사용하여 Objective C 프로그램을 컴파일하고 실행할 수 있다. 커맨드 라인은 Unix/Linux 커맨드 라인과 비슷하고 Windows 머신의 모든 폴더에 접근할 수 있다. 내장(built in) gcc 프로그램을 이용하여 Objective C 프로그램을 컴파일하고 실행할 수 있다.

윈도우즈에서 Objective C 프로그램 컴파일하고 실행하기

메모장을 이용하여 아래 코드를 입력하고 helloworld.m 으로 저장하라.

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

이제 GNUStep 셀을 이용하여 helloworld.m 이 저장된 곳으로 이동하자. 그리고 아래 명령어를 입력하자.

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

-lobjc 와 같은 다양한 스위치 옵션들은 명령어의 마지막에 나타나야 한다는 것을 기억하라. -o 스위치는 실행화일의 이름을 나타낸다. 아래는 컴파일 결과 화면이다.

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 DLL

같은 폴더에 helloworld.exe 가 생성된 것을 볼 수 있을 것이다. (컴파일러 출력과 경고를 무시하라 아니면 그것들을 고치기 위해 -enable-auto-imports 스위치를 사용하라.) 프로그램을 실행하기 위해서는 ./helloworld.exe 를 입력하라.

출처 : http://www.jayson.in/programming/objective-c-programming-in-windows-gnustep-projectcenter.html