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

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

  第二、安装GNUStep,

yum安装

根据https://www.cnblogs.com/zenny-chen/p/4080067.html的提示,可以通过apt-get install gnustep和apt-get install gnustep-devel安装,在CentOS系统下,首先想通过yum安装,但是,yum list yum list \*step\* 却找不到gnustep,这里需要在/etc/yum.repos.d/添加一个epel.repo【可以通过yum install epel-release或者wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm获得rpm安装】,然后通过 yum list \*step\*,可以看到虽然项目的名字是GNUstep,但是在yum的列表里却是gnustep,

通过命令yum install gnustep-base gnustep-base-devel gnustep-base-doc gnustep-base-libs gnustep-filesystem gnustep-make gnustep-make-doc 安装gnustep的make、base、libs等。

如果遇到:GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7"

可以关掉gpg的key的检查来继续完成安装,关闭的方法就是修改/etc/yum.repos.d/epel.repo,将gpgcheck=1改成gpgcheck=0,就可以安装成功了。

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

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

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

参考:

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

http://wiki.gnustep.org/index.php/GNUstep_SVN_Installation_Guide

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

https://www.techotopia.com/index.php/Building_and_Installing_GNUstep_on_Linux

http://wiki.gnustep.org/index.php/Dependencies

http://wiki.gnustep.org/index.php/Platform:Linux

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

发布了85 篇原创文章 · 获赞 9 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/jimmyleeee/article/details/104945181