Instalacja SDK (Software Development Kit) i podstawy jego używania
From MorphOS Library
Grzegorz Kraszewski
Ta strona w innych językach: angielski
Instalacja SDK
Oficjalny pakiet SDK (Software Developer Kit) MorphOS-a zawiera komplet narzędzi niezbędnych do tworzenia programów dla tego systemu. Znajdują się w nim następujące elementy:
- pliki nagłówkowe systemu (dla natywnego API MorphOS-a).
- pliki nagłówkowe standardowej biblioteki C i C++.
- Dokumentacja API MorphOS-a i przykładowe kody źródłowe.
- Dwie wersje kompilatora GCC: 2.95.3 i 4.4.4.
- Zestawy programów towarzyszących GCC (tzw. toolchains), jeden zestaw dla każdego kompilatora, inne narzędzia dla programistów.
- MorphED, prosty edytor programisty.
- Język skryptowy Perl, używany przez niektóre z narzędzi.
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.4. There is a tool named GCCSelect in the SDK, which allows fast switching between compilers. Just type in a shell window
GCCSelect 2.95.3
or
GCCSelect 4.4.4
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 4.4.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.4.4 is recommended, as the old one simply does not keep up with modern standards.
- 4.4.4 usually produces faster code (but sometimes also bigger, depending on optimizer options).
- 4.4.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.