삽질하는플머

윈도에서 Objective-C 개발환경 만들기

탐구생활/Objective-C
아직 뭐가뭔지 잘 모르겠지만, GNUStep 이라는 플랫폼을 이용해 윈도에서 Objective-C 개발환경을 구축할 수 있다. 


GNU Step 사이트 에서 GNUstep System 과 GNUStep Core 를 다운받아 설치한다. 중간에 rxvt 설정부분은 무시하고 그냥 깔기만 하면 된다. 

설치 후 뜨는 MSys의 셸이 복사/붙이기가 잘 안되는 문제가 있으니 DKW를 셸로 사용하자. GNUStep 의 디렉토리에 DKW 실행파일과 INI를 복사하고 이름을 각각 GNUStep.exe, GNUStep.ini 로 바꾼다. GNUStep.ini 의 exec 항목을 다음과 같이 바꿔준다.  

exec=C:\GNUstep\bin\sh.exe --login -i


한글 입출력을 원활히 하기 위해 .inputrc 수정

set output-meta on
set convert-meta off


환경설정, 프롬프트 및 ls 색 변경, 침침한 셸 색상 변경을 위해 .profile 파일 추가. 

PS1="[\u@\h \W]\\$ "
alias ls="ls --color=auto --show-control-chars"

BGCOLOR=black
FGCOLOR=#AFAFAF

/GNUStep/System/Library/Makefiles/GNUstep.sh


이제 익숙한 셸 환경이 보인다. 우헤~~




다음과 같이 source.m 파일을 만들고

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

int
main (void)
{
  NSAutoreleasePool *pool;

  pool = [NSAutoreleasePool new];

  [NSApplication sharedApplication];

  NSRunAlertPanel (@"Test", @"Hello from the GNUstep AppKit",
                   nil, nil, nil);

  return 0;
}


GNUMakefile 을 다음과 같이 만들어준다. 

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = PanelTest <---------- 실행파일 이름
PanelTest_OBJC_FILES = source.m <--- 소스파일 이름

include $(GNUSTEP_MAKEFILES)/application.make


콘솔창에서 make를 때리면 빌드. 햐~~ 맥에서의 어플과 마찬가지로 *.app를 가지는 디렉토리가 떨어진다. 
컴파일이 다 끝났으면 실행. 

$ openapp ./PanelTest.app


NS객체를 쓰지 않는 다음과 같은 hello.m 은 GCC명령 한방으로 컴파일되니 함 돌려보세. 

#import <stdio.h>

int main (int argc, const char *argv[]) {
  printf( "Hello world\n");
  return 0;
}

gcc -o hello.exe hello.m





이 위키의 다음 페이지에서는 Dev-C++ 을 사용한 통합환경 꾸미기에 대해서도 설명되어있다.  


Dev-C++ MinGW없는 버전을 받아 설치한다. 

메뉴의 Tools(도구) > Compiler Options(컴파일러 설정) > Compiler(컴파일러)  를 열고 컴파일러 추가명령에 다음을 등록한다. 

-lobjc -lgnustep-base -fconstant-string-class=NSConstantString -enable-auto-import

링커 추가명령도 동일하게 지정한다. 




디렉토리의 각 항목에 다음과 같이 입력해준다. 

실행파일들
C:\GNUstep\mingw\bin
C:\GNUstep\bin

라이브러리
C:\GNUstep\mingw\lib
C:\GNUstep\GNUstep\System\Library\Libraries

C Include
C:\GNUstep\mingw\include
C:\GNUstep\GNUstep\System\Library\Headers


파일 -> 새로 만들기 -> 프로젝트 메뉴를 클릭하고 Empty Project 를 골라준다. 언어설정은 C로 해준다. 




프로젝트에서 유닛추가를 하고 이름을 적당히 바꿔준다. 이 때 확장자는 *m으로 한다. 

적당한 프로젝트를 빌드해보면... 뭐 대충 잘 되는군. 


----
2010.11.23

컴파일러 설정을 바꿔봄. 
* 컴파일러 추가 명령
-fconstant-string-class=NSConstantString

*링커 추가 명령
-lobjc -lgnustep-base -enable-auto-import




이 상태에서 추가로 AppKit 을 사용하는 경우 프로젝트 옵션의 매개변수에서 링커에 다음 항목을 추가한다. 
-lgnustep-gui 





다음 코드를 테스트. 

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

int main (void)
{
  NSAutoreleasePool *pool;

  pool = [NSAutoreleasePool new];

  [NSApplication sharedApplication];

  NSRunAlertPanel (@"Test", @"Hello from the GNUstep AppKit",
                   nil, nil, nil);

  return 0;
}


실행결과는 뭐 잘 돌아가는군. 











Objective-c Beginner's guide






윈도에서의 gcc

Delphi to Cocoa. 컨셉 비교.