In
Installing and Using GNUstep and Objective-C on Linux, we covered the steps involved in installing the GNUstep environment on Linux distributions for which pre-built GNUstep packages are available. Unfortunately, very few Linux distributions have pre-built
packages available making it necessary download and build the GNUstep sources on most systems.
The purpose of this chapter of
Objective-C 2.0 Essentials is to outline the steps necessary to download and build the GNUstep sources. The process outlined here is known to work on Fedora, Red Hat Enterprise Linux and CentOS. The steps should be largely similar for other Linux distributions,
though the exact command to perform package installations may differ from the one used here. For details on how to install specific packages for your chosen Linux distribution it may be necessary to refer to the corresponding documentation.
Installing gcc and Objective-C Support on Linux
The first step in the build process is to install gcc together with the gcc Objective-C package. These packages are calledgcc and
gcc-obj respectively and on Red Hat, Fedora and CentOS systems may be installed as follows:
su -
yum install gcc
yum install gcc-objc
Once installed, the next step is to resolve some additional package dependencies.
Package Dependencies
A Linux distribution is essentially a Linux kernel and a range of packages. Each distribution consists of a vast array of packages, many of which are not installed by default when the operating system is first installed. The idea behind this is to keep the
size of the installed operating system to a minimum, encouraging users to only install a package when they actually need it. Consequently, there are many packages upon which GNUstep is dependent that are not installed by default on most Linux systems. Before
we can embark on a GNUstep environment build, therefore, it is necessary to install these package dependencies. Fortunately, these can be installed using a single command:
yum install make libpng libpng-devel libtiff libtiff-devel libobjc libxml2 libxml2-devel
libX11-devel libXt-devel libjpeg libjpeg-devel
Keep in mind that some of these packages may already be installed, in which case the package manager will simply move on to the next package. In addition, many of these packages will have dependencies of their own which will be added to the installation
process automatically.
Once the packages are installed we are ready to download the GNUstep source code.
Obtaining the GNUstep Source Code
<style type="text/css">
<!--
-->
</style>
The GNUstep core consists of the following packages:
- GNUstep Make
- GNUstep Base
- GNUstep GUI
- GNUstep Backend
Each of these packages needs to be built and installed on your Linux system in order to gain access to the full power of Objective-C and to be able to work with the examples in the remainder of this book. Fortunately a single package calledGNUstep Startup
is provided that contains the source code for all four of the above packages. This package can be downloaded from theGNUstep.org
website download page. Be sure to download the latest stable release of theGNUstep Startup software.
Once the package has been downloaded to a suitable work folder it can be unpacked as follows (where <version> is replaced by the version number of the package you downloaded):
tar xvfz gnustep-startup-<version>.tar.gz
The source files will be unpacked into a new directory named gnustep-startup-<version> (once again substituting <version> for the version you downloaded). Change directory into this folder as follows:
cd gnustep-startup-<version>
Configuring the Build Process
Before the build process can be started it must first be configured. This is an automated process that scans the system on which the build is to take place to find out about the packages that are installed and then creates a build configuration file and
a Makefile. This configuration is performed by executing the following command in the GNUstep directory created in the previous section of this chapter:
./configure
Building GNUstep
Once the configuration script process is complete it is time to begin the GNUstep build. This is achieved by typing the following command:
make
Once executed, the build process will display an opening message similar to the following:
GNUstep Installation
This is an automatic installation script for GNUstep.
This script tries to build and install the core libraries for
GNUstep. Log files of the build process are kept so that if some
part of the build does not work, you can send the log files to
our attention (at bug-gnustep@gnu.org). From these we can try to
determine what the problem is.
Press the Return key to begin continue:
Press any key to continue to the system check phase. At the end of this phase a list of errors and warnings may appear. Any errors will prevent the build from completing and should be addressed before proceeding. These typically involve installation of missing
packages. Warnings can usually be ignored without impacting the subsequent build process.
Having reviewed the information provided, press any key to return to the build. The duration of the build will depend on the speed of the system but will usually be completed within a few minutes and display a message containing information some useful information:
---------------------------------------------------------
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
Perhaps the most important piece of information in the above output is the reference to theGNUstep initialization script. This must be run prior to compiling any Objective-C applications and can be placed in the .bashrc startup script in your home
directory. Make a note of the location listed in the message on your screen as the exact location may differ from the one shown above.
Testing the Objective-C and GNUstep Installation
Once the installation is complete, it can be tested by opening your favorite editor (if you don't have a favorite try GEdit by selecting Applications->Accessories->Text Editor) and entering some Objective-C code:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog (@"hello world");
[pool drain];
return 0;
}
Objective-C source files have a .m file name extension, so save the file ashello.m in a suitable folder such that you will be able to locate the file in the next section.
Compiling Objective-C Code
Before an Objective-C program can be run it must first be compiled. Compilation is a process whereby the human readable Objective-C code in the source file (in our case hello.m) is converted to the machine code understood by the CPU. Prior to performing
this compilation, however, the GNUstep environment must first be set up by executing theGNUstep.sh, the location of which was provided at the end of the installation process. Execute this script exactly as outlined in the installation message, for
example:
. /usr/GNUstep/System/Library/Makefiles/GNUstep.sh
Failure to execute this script prior to compiling Objective-C code in a Terminal window will result in the compiler reporting errors similar to the following:
error: cannot find interface declaration for ‘NXConstantString’
From within a Terminal window change directory to the where you saved the hello.m source file and execute the following command to compile it:
gcc `gnustep-config --objc-flags` -L/usr/GNUstep/Local/Library/Libraries -lgnustep-base hello.m -o hello
If all goes well, the compilation should complete silently and the test application is ready to run. The program may be executed as follows:
./hello
Executing the program will result in output similar to the following:
2009-09-15 10:48:39.772 prog1[12906] hello world
Assuming you see output similar to the above example, Objective-C and GNUstep are successfully installed on your Linux system and you are ready to continue with the remainder of this book.
分享到:
相关推荐
一套windows下编译OC的工具,GNUstep 其实打造类似 KDE 或 GNOME 的整合式环境,只是说它用 的程式语言是 Object C , 而本身也有一套 GUI Toolkits 来开发
GNUstep安装文件,总共四个文件,这是其中一个
在 1995 年, 自由軟體基金會 (Free Software Fundation) 開始了 GNUstep 計劃, 目的在實作 OpenStep 介面, 以提供 Linux/BSD 系統一個完整的程式發展環境. 但由於 OpenStep 介面過於龐大, 開發人力不足, 及許多技術...
gnustep-grom 编译一个窗体文件源码
GNUstep Objective C iPhone Apple GNUstep Objective C iPhone Apple GNUstep Objective C iPhone Apple
GNUstep安装包 支持 Objective-C 语言,,其中只有system和core
入门使用这本 Vagrantfile 和 Chef 食谱,您有两个主要选择: (推荐)安装 Vagrant 和 VirtualBox 并使用随附的 Vagrantfile 创建和配置 VM 使用具有受支持操作系统的现有虚拟机,并在没有 Vagrant 的情况下引导...
If you want to compile and develop your own GNUstep applications, also install the gnustep-devel package
gnustep-devel-1.4.0-setup.exe
GNUStep gnustep-msys-system-0.28.1-setup.exe object-c开发环境,window下搭建object-c开发环境。
GNUStep gnustep-devel-1.3.0-setup.exe object-c开发环境,window下搭建object-c开发环境。
gnustep-cairo-0.22.1-setup.exe 苹果开发必备
可以使用GNUstep在Windows XP上寫Objective-C程式,但是Objective-C已經加了很多新東西,而GNUstep裡的gcc並不提供,所以,这个是GNUstep,再加上新一代的編譯器架構Clang與LLVM(這也是Apple在新版Xcode裡預設使用...
scons 在windwos下编译objective-c 的脚本,在windwos环境下写测试用例使用。前提是机器上已安装了gnustep工具,四个常用的工具,http://blog.csdn.net/tomatofly/article/details/6034116 作参考。
GNUstep object-c函数学习手册 帮助你学习oc
windows苹果开发平台,适合没有虚拟化功能的电脑。
the gnustep-msys-system package
gnustep 核心包
GNUstep Objective C iPhone Apple GNUstep Objective C iPhone Apple GNUstep Objective C iPhone Apple GNUstep Objective C iPhone Apple
GNUstep Objective C iPhone Apple GNUstep Objective C iPhone Apple