UBUNTU 시스템에서 Objective-C 프로그램 언어 사용하기
1. 터미널 창에서 아래의 명령을 이용하여 개발에 필요한 구성 요소를 설치합니다.
l sudo apt-get -y install gnustep
l sudo apt-get install gnustep-devel
l sudo apt-get -y install build-essential
l sudo apt-get install gobjc
l sudo apt-get install gnustep-make
l sudo apt-get install libgnustep-base-dev
2. Ubuntu Software Center 도구를 이용하여, 그림과 같이 “OpenStep”으로 검색하면, 설치된 구성 요소를 확인 할 수 있습니다.
3. Text Editor 프로그램을 이용하여, 아래와 같이 소스 코드를 작성합니다. #import <Foundation/Foundation.h> int main (void) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello, World!"); [pool drain]; return 0; } l 작성된 소스 코드를 “hello.m” 파일로 저장합니다. 4. 처음으로 Objective-C 파일을 컴파일 하는 경우, 아래의 작업을 먼저 수행한다. account@ubuntu:~$ /usr/share/GNUstep/Makefiles/GNUstep.sh bash: /usr/share/GNUstep/Makefiles/GNUstep.sh: Permission denied account@ubuntu:~$ account@ubuntu:~$ sudo chmod +wx /usr/share/GNUstep/Makefiles/GNUstep.sh account@ubuntu:~$ account@ubuntu:~$ ls -lt /usr/share/GNUstep/Makefiles/GNUstep.sh -rwxrwxrwx 1 root root 22517 2010-06-05 00:37 /usr/share/GNUstep/Makefiles/GNUstep.sh account@ubuntu:~$ account@ubuntu:~$ /usr/share/GNUstep/Makefiles/GNUstep.sh account@ubuntu:~$ l /usr/share/GNUstep/Makefiles/GNUstep.sh 스크립트를 이용하여, Objective-C 언어를 컴파일 할 수 있는 터미널 환경을 만들어 주어야 합니다. (새로운 터미널 창을 생성할 때마다 이 스크립트는 수행되어야 합니다.) l 처음 스크립트를 실행하는 경우, 권한 오류가 나타날 수 있는데, 그러한 경우 chmod 명령을 이용하여, 실행할 수 있는 권한을 부여합니다. 5. 터미널 창에서 파일이 저장된 위치로 디렉터리를 이동하여, 컴파일을 시도해보겠습니다. account@ubuntu:~/Project$ gcc hello.m -o hello hello.m:1:34: fatal error: Foundation/Foundation.h: No such file or directory compilation terminated. account@ubuntu:~/Project$ account@ubuntu:~/Project$ gcc hello.m -o hello -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ In file included from /usr/include/GNUstep/Foundation/NSClassDescription.h:30:0, from /usr/include/GNUstep/Foundation/Foundation.h:49, from hello.m:1: /usr/include/GNUstep/Foundation/NSException.h:42:2: error: #error The current setting for native-objc-exceptions does not match that of gnustep-base ... please correct this. hello.m: In function ‘main’: hello.m:6:3: error: cannot find interface declaration for ‘NXConstantString’ account@ubuntu:~/Project$ account@ubuntu:~/Project$ gcc hello.m -o hello -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -lgnustep-base In file included from /usr/include/GNUstep/Foundation/NSClassDescription.h:30:0, from /usr/include/GNUstep/Foundation/Foundation.h:49, from hello.m:1: /usr/include/GNUstep/Foundation/NSException.h:42:2: error: #error The current setting for native-objc-exceptions does not match that of gnustep-base ... please correct this. hello.m: In function ‘main’: hello.m:6:3: error: cannot find interface declaration for ‘NXConstantString’ account@ubuntu:~/Project$ account@ubuntu:~/Project$ gcc `gnustep-config --objc-flags` hello.m -o hello -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -lgnustep-base account@ubuntu:~/Project$ ls hello hello.d hello.m account@ubuntu:~/Project$ ./hello 2011-06-17 19:10:26.336 hello[2162] Hello, World! account@ubuntu:~/Project$ l gcc 컴파일러가 제대로 동작하기 위해서 여러 실행 인자를 함께 구성하여, 명령을 수행하게 해야 합니다. l 실행 인자 “gnustep-config”와 함께 컴파일과 링크를 수행하면, 실행 파일 “hello”가 정상적으로 출력되는 것을 확인할 수 있습니다.
[...] 求助于万能的google,在一韓文博客上找到答案,。 正确的编译命令: gcc `gnustep-config –objc-flags` hello.m -o hello -I /usr/include/GNUstep/ -L /usr/lib/GNUstep/ -lgnustep-base [...]
Pingback by Objective-C的hello world | 阳光烂灿的日子 — 2011.09.30 @ 16:38 |
Thanks for that beginner friendly tutorial. works! Greetings from germany.
Comment by anonym — 2012.10.01 @ 17:02 |
[...] also be done on Linux platform. I am using Debian and have set up the environment after refering this post. Here are the brief [...]
Pingback by Compile Object-C program in command line | 湖间小筑 — 2013.01.24 @ 02:08 |
See also http://stackoverflow.com/questions/11358000/how-to-compile-objective-c-code-in-ubuntu
The error: cannot find interface declaration for ‘NXConstantString’ is probably taken care of by
-fconstant-string-class=NSConstantString
Comment by Faheem Mitha — 2013.02.03 @ 19:36 |