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.
分享到:
相关推荐
GNUstep的目标是跨平台,使得开发者能够在不同的操作系统上,如Linux、FreeBSD、Windows等,构建和运行Objective-C应用。 GNUstep的核心组件包括一个编译器(GCC)、一个运行时系统、一系列基础类库(Foundation和...
- **安装**: GNUStep可以在多种平台上进行安装,包括Linux/BSD等系统。安装过程相对简单,可通过包管理器或源码编译完成。 - **用户配置**: 用户可以通过设置来个性化GNUStep环境,例如语言选择、字体大小等。 - **...
Gnustep为非Apple平台,如Windows、Linux、FreeBSD等提供了类似的功能,使得开发者可以在这些平台上构建与Cocoa相似的应用程序。 标题中的“gnustep几个包”可能是指在Gnustep环境中包含的一系列核心组件和开发工具...
在安装并配置GNUStep后,开发者将能够: 1. 使用GCC编译Objective-C源代码。 2. 访问GNUStep的类库,这些类库实现了Objective-C的Foundation和AppKit框架,为创建应用程序提供了基础。 3. 利用Makefile或者其他的...
在安装GNUstep时,用户需要了解以下关键知识点: 1. **Objective-C编程语言**:GNUstep是基于Objective-C的,这是一种面向对象的编程语言,扩展了C语言,特别适合于构建图形用户界面和应用程序框架。 2. **跨平台...
在`gnustep-core-0.23.0-setup.exe`和`gnustep-cairo-0.22.1-setup.exe`的安装过程中,`GNUmakefile`可能用于指导编译和安装步骤,确保所有依赖项正确地链接和配置。这通常包括下载源代码、编译源代码、创建库和可...
- 首先,你需要下载一系列的GNUstep相关软件包,包括MinGW(Minimalist GNU for Windows),这是GNU编译工具集在Windows上的移植。你可以从官方FTP站点(http://ftpmain.gnustep.org/pub/gnustep/binaries/windows/...
总结来说,在Windows系统下搭建Objective-C开发环境虽然不像在Mac OS X上那样直接便捷,但通过使用GNUstep等工具,我们依然可以实现在Windows系统下的Objective-C开发。希望这份详细的指南能够帮助那些需要或希望在...
对于Windows用户来说,可以直接下载适用于win32平台的MinGW版本,该版本是预编译好的,无需用户自行在Linux环境下编译。下载完成后,将Swarm解压到合适的位置,例如C:\swarm目录。 为了确保系统能够识别Swarm的执行...
通过这个简易的过程,你可以在Windows上开始你的Objective C学习之旅,尽管这并不等同于在Xcode(Apple的官方IDE)上开发,但足以让你理解和编写Objective C代码。随着学习的深入,你可能还需要了解更多的Objective ...
其中,Motif是商业化的工具箱,而在Linux下,其开源替代品LessTif也能支持许多基于Motif开发的应用。 Open Look和GNUstep是早期尝试建立X Window界面风格标准的系统,旨在跨多种主机平台提供一致的用户体验。Sun ...
在Linux/FreeBSD环境下,为了编译GNUstep应用程序,需要安装GNUstep环境并进行相应的配置。 - **安装步骤**:首先安装GNUstep。安装后,找到GNUstep.sh脚本文件,该文件通常位于`/usr/GNUstep/System/Makefiles/`...
它可以在Windows和OS X上成功运行,现已被Linux使用。 依存关系 Psychrometrics C / C ++库(从下载) Mac OS X 应该在开有Xcode的Mac OS X上进行编译。 Linux 建立基本要素 Gnustep Gnustep-devel 提供了一个...
在编译和环境设定方面,教程指出不同操作系统环境下设置Objective-C开发环境的方法,如在Linux或FreeBSD上安装GNUStep,MacOSX上安装XCode等。这为初学者提供了开发环境的搭建指南。 Objective-C中的类定义分为接口...
在Linux或FreeBSD上要安装GNUStep,在Mac上需要安装XCode,在Windows NT 5.X上则需要安装cygwin或mingw,并安装GNUStep。 17. Objective-C与C的关系: Objective-C是C语言的超集,这意味着任何标准C语言程序都是有效...
对于环境设定,如果是在Linux/FreeBSD系统上,需要安装GNUStep,并执行特定的shell脚本来配置环境。在MacOSX上,需要安装XCode,而在Windows系统上,则需要安装Cygwin或MinGW以及GNUStep。 2. Objective-C基础语法...
16. 编译与环境设定:介绍了如何在不同的操作系统环境下设置开发环境以及编译Objective-C代码,例如在Linux/FreeBSD上安装GNUStep,在Mac OS X上安装XCode,在Windows NT5.X上安装cygwin或mingw。 本教程在前言部分...
GNUStep是一个开源的Objective-C运行环境,它提供了一组工具和库来帮助开发者在非Apple平台上进行Objective-C编程。 - **安装步骤**: - 访问官方网站http://www.gnustep.org/experience/Windows.html下载所需安装...
- **Linux/FreeBSD**: 使用GNUStep。安装步骤包括解压并运行`GNUstep.sh`脚本来完成配置。 - **Mac OS X**: 使用XCode进行开发。 - **Windows NT 5.X**: 可以通过cygwin或mingw配合GNUStep来实现。 ### 编译...