如何在CentOS7系统上编译Object-C的项目-源码安装篇

源码安装相对于yum安装比较麻烦,就是在不停地遇到错误解决错误,网站(http://wwwmain.gnustep.org/resources/downloads.php?site=ftp%3A%2F%2Fftp.gnustep.org%2Fpub%2Fgnustep%2F#core)对于依赖的说明也不全面 按照网站说明安装依赖,依然会缺少一些比较重要的依赖包,例如:xslt、gnutls等。如果不需要依赖的包就可以使用--disable-xx,xx是包名,例如:--disable-gnutls。

第一步、如果要在CentOS系统上编译Object-C项目,首先必须安装gcc-objc, 可以通过yum安装:yum install gcc-objc。

 第二、安装GNUStep,源码安装

如果要了解GNUStep可以参考http://www.gnustep.org/,下载地址http://ftpmain.gnustep.org/pub/gnustep/core/ ,默认安装目录是/usr/GNUstep,原安装指导文档:http://wiki.gnustep.org/index.php/GNUstep_SVN_Installation_Guide

在安装之前,根据http://wwwmain.gnustep.org/resources/downloads.php?site=ftp%3A%2F%2Fftp.gnustep.org%2Fpub%2Fgnustep%2F的提示,需要安装GNUstep的依赖,但是提示的并不全面,可以通过下面的命令把所有依赖的库都提前安装:

yum install make libpng libpng-devel libtiff libtiff-devel libobjc libxml2 libxml2-devel libX11-devel libXt-devel libjpeg libjpeg-devel   libxslt libxslt-devel  gnutls gnutls-devel libicu libicu-devel libobjc libffi libffi-devel

通过wget http://ftpmain.gnustep.org/pub/gnustep/core/gnustep-startup-0.32.0.tar.gz 获得gnustep的源码

安装步骤如下:

[root@osboxes ~]# cd ~
[root@osboxes ~]# tar xzvf gnustep-startup-0.32.0.tar.gz
[root@osboxes ~]# cd gnustep-startup-0.32.0/
[root@osboxes ~]# ./InstallGNUstep

安装成功会显示:

为了避免每次登录都需要运行  . /usr/GNUstep/System/Library/Makefiles/GNUstep.sh  可以执行一下命令。

[root@osboxes ~]# echo '. /usr/GNUstep/System/Library/Makefiles/GNUstep.sh' >> /etc/profile
[root@osboxes ~]# source /etc/profile

如果遇到:错误:configure: error: Incomplete support for ffi functionality.

解决方案:可以使用 yum libffi libffi-devel 安装,也可以根据 readme的提示需要添加:” --ffi=libffi ”, 运行 /InstallGNUstep --ffi=libffi  安装。

系统依赖的一些包在网站上并没有全部罗列出来,在安装的过程中需要根据需要选择是否使用相关的包,以下是几个可能遇到的包:

如果遇到:You do not appear to have usable libxslt headers/library.
解决方案:yum install  libxslt libxslt-devel


如果遇到: You do not appear to have usable libgnutls headers/library.
执行 yum install gnutls 缺发现找不到gnutls, 执行 yum -y install epel-release, 然后再执行 yum install gnutls才可以。
解决方案:yum install gnutls gnutls-devel

如果遇到:You do not appear to have usable ICU headers/libraries. 根据http://site.icu-project.org/,可以知道ICU是一个处理Unicode和全球化的库

ICU is a mature, widely used set of C/C++ and Java libraries providing Unicode and Globalization support for software applications. ICU is widely portable and gives applications the same results on all platforms and between C/C++ and Java software. 

解决方案:可以简单一点使用yum安装:yum install libicu libicu-devel

解决方案:也可以源码安装,下载页面:https://github.com/unicode-org/icu/releases/tag/release-66-1,找到需要下载的版本使用wget下载:wget https://github.com/unicode-org/icu/releases/download/release-66-1/icu4c-66_1-src.tgz。根据编译的说明也可以执行一下命令编译:

git clone export https://github.com/unicode-org/icu.git
mkdir icu4c-build
cd icu4c-build
../icu/icu4c/source/runConfigureICU Linux
make check

第三步,安装 Gorm, Graphical interface builder  (根据需求可选,依赖网页上描述的是 推荐安装)

wget http://ftpmain.gnustep.org/pub/gnustep/dev-apps/gorm-1.2.24.tar.gz

tar -zxvf gorm-1.2.24.tar.gz

cd gorm-1.2.24

make install

第四步,安装 Project Center, Project developer(根据需求可选,依赖网页描述的是 推荐安装)

wget http://ftpmain.gnustep.org/pub/gnustep/dev-apps/ProjectCenter-0.6.2.tar.gz

tar -zxvf ProjectCenter-0.6.2.tar.gz

cd cd ProjectCenter-0.6.2

make install

最后,通过以下程序测试环境是否安装成功,将其保存为hello.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的环境:

. /usr/GNUstep/System/Library/Makefiles/GNUstep.sh      * 注意前面的点不能少。

然后执行 

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

如果遇到:/bin/ld: cannot find -lgnustep-base

需要把gnustep-base的路径设置一下:

通过 find / -name gnustep-base*  找到 gnustep-base的库在哪一个路径下,然后在编译的时候带上即可。

gcc `gnustep-config --objc-flags` -Wl,--no-as-needed -lgnustep-base -L/usr/GNUstep/System/Library/Libraries -fconstant-string-class=NSConstantString  -lobjc hello.m -o hello

如果编译成功,直接执行 ./hello。

 CentOS环境下,Object-C的编译和执行搞定。

 

参考:

https://www.tutorialspoint.com/objective_c/objective_c_environment_setup.htm

http://wwwmain.gnustep.org/resources/downloads.php?site=ftp%3A%2F%2Fftp.gnustep.org%2Fpub%2Fgnustep%2F

http://ftp.gnustep.org/pub/gnustep/core/

http://gnustep.made-it.com/BuildGuide/index.html#BUILDING.GNUSTEP

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值