Installation of Software Development Kit and its basic usage
From MorphOS Library
Grzegorz Kraszewski
This page in other languages: polski
Installing the SDK
The official MorphOS SDK provides a complete environment for creating programs for MorphOS. It contains the following components:
- MorphOS includes (for the MorphOS native API).
- Standard C and C++ library includes.
- MorphOS API documentation and example code.
- Two GCC compilers, 2.95.3 and 4.4.5.
- GCC toolchains (one for each compiler), sets of developer utility programs.
- Scribble, an advanced programmer's editor with syntax highlighting and powerful autocomplete and code analyser/hinter feature (starting from SDK 3.2 Scribble has been moved to the base system).
- Perl scripting language (used by some SDK tools).
The first step of installation is to download the SDK archive from the morphos.net site, or by clicking this direct link. The SDK is delivered as a LhA archive, which must be depacked before proceeding. The easiest way is to open a context menu for the archive (with the right mouse button in an Ambient window) and choose Extract. After depacking a directory named morphossdk is created with an Installer application and a big file named sdk.pack inside. Installation is started by running Installer. The only user choice that is needed here is to choose an installation directory. Then there is some time spent watching the progress bar...
After the installation a system reboot may be needed to update system assigns and paths.
Choosing a Compiler
As mentioned above, the SDK delivers two GCC compilers: an old but trusty 2.95.3 one, and the modern 4.4.5. There is a tool named GCCSelect in the SDK, which allows for fast switching between compilers. Just type in a shell window
GCCSelect 2.95.3
or
GCCSelect 4.4.5
to change the current compiler. GCCSelect works by making symbolic links to the proper version of GCC and its tools, so the compiler is always called as gcc or g++, regardless of the version chosen currently.
Which one to choose? It depends on the code compiled and other constrains. Here is some guidance:
- 2.95.3 compiles faster and consumes less memory.
- For old code 2.95.3 would be better, as GCC 4 will produce tons of warnings or even errors on code being flawlessly compiled by the old GCC.
- For new projects, especially written in C++, GCC 4 is recommended, as the old one simply does not keep up with modern standards.
- GCC 4 usually produces faster code (but sometimes also bigger, depending on optimizer options).
- GCC 4 is a relatively new and complex compiler, may contain more bugs than 2.95.3.
My general advice is to use GCC 4 and only switch to GCC 2 if needed.
One can check which compiler is currently active using the −v compiler option, which displays the compiler version and build options:
gcc -v
The last line of output shows the GCC version.
Standard C and C++ Libraries
These standard libraries are parts of the C and C++ language specifications respectively. They mainly deliver file and console input/output functions, mathematic functions and string operations. The C++ library also provides a set of basic container classes.
There are two ways to access these libraries on MorphOS. The first (and default) one is by using a MorphOS shared library; ixemul.library. As the name suggests, this library tries to provide some Unix environment emulation on MorphOS, which, other than the standard libraries, includes large part of POSIX standard and some other commonly used functions. ixemul.library is usually used for porting big projects from the Unix/Linux world, for example it is used by GCC itself and many other tools in the SDK.
The second way is to use libnix (as in; lib no ixemul). In contrast to ixemul.library, libnix is statically linked with the application. This is the preferred way for providing standard libraries for MorphOS native applications. It is achieved by passing the −noixemul flag to the compiler and the linker. libnix delivers full C and C++ standard libraries, but its POSIX implementation is less complete.
Another alternative is to not use standard libraries at all. It may sound crazy at first, but the MorphOS native API provides complete file and console I/O as well as some string manipulation functions and many mathematic functions. Using the native API makes applications faster and smaller in size. On the other hand code using the MorphOS API directly is not portable to non-Amiga(like) systems. A −nostdlib compiler option instructs the compiler to not link the code with the standard library. Note that this requires also writing your own custom startup code.