在Centos7上搭建Objective-C环境
How to deploy Objective-C Environment on CentOS 7
2021-06-25 18:09:06
Devops
301

1. 安装gcc和gcc Objective-C包:

$ yum install gcc

$ yum install epel-release

$ yum install gcc-objc

2. 安装依赖包:

$ sudo yum install make libpng libpng-devel libtiff libtiff-devel libobjc libxml2 libxml2-devel libX11-devel libXt-devel libjpeg libjpeg-devel

$ sudo yum -y install gnustep-base gnustep-base-devel gnustep-base-doc gnustep-base-libs gnustep-filesystem gnustep-make gnustep-make-doc gnutls gnutls-devel

3. 为了支持完整的Objective-C特性, 需要安装GNUStep组件,由于并没有现成的GNUStep组件可供安装,需要下载源码编译并安装。

源码下载地址http://ftpmain.gnustep.org/pub/gnustep/core/  本人下载的版本是gnustep-startup-0.32.0.tar.gz 默认安装目录是/usr/GNUstep。

# cd ~
# wget http://ftpmain.gnustep.org/pub/gnustep/core/gnustep-startup-0.32.0.tar.gz
# tar xzvf gnustep-startup-0.32.0.tar.gz
# cd gnustep-startup-0.32.0/
# ./InstallGNUstep
# echo '. /usr/GNUstep/System/Library/Makefiles/GNUstep.sh' >> /etc/profile
# source /etc/profile

4. 测试环境是否安装成功

新建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;
}
# gcc `gnustep-config --objc-flags` -L/usr/GNUstep/System/Library/Libraries -lgnustep-base -lobjc helloWorld.m -o helloWorld
# ./helloWorld
2016-05-13 13:55:23.943 helloWorld[24188] hello world

gcc `gnustep-config --objc-flags` -lgnustep-base hello.m -o hello 如果遇到;undefined reference to symbol 'objc_msg_lookup' 需要在编译的时候加上选项 -lobjc gcc `gnustep-config --objc-flags` -lgnustep-base -lobjc hello.m -o hello 如果遇到“error: cannot find interface declaration for ‘NXConstantString’”, 则需要在编译的命令行加上“-fconstant-string-class=NSConstantString”, gcc `gnustep-config --objc-flags` -Wl,--no-as-needed -lgnustep-base -fconstant-string-class=NSConstantString  -lobjc hello.m -o hello
---------------------------------------------------------

Installation Finished

---------------------------------------------------------

Now run the GNUstep initialization script (put this in your
.bashrc or other type of startup script). Note the '.' at the
beginning of the line.
. /usr/GNUstep/System/Library/Makefiles/GNUstep.sh

Now you can install some applications and start using GNUstep
Look for a few applications in the AppSources directory. The
typical way to install an application is:
  tar -zxf MyApplication.tar.gz
  cd MyApplication
  make
  make install (as root, unless GNUstep is in your home dir)

Then start the application:
  openapp MyApplication.app

参考文档:http://www.tutorialspoint.com/objective_c/objective_c_environment_setup.htm