Difference between revisions of "Installation of Software Development Kit and its basic usage"

From MorphOS Library

m (Standard C and C++ Libraries: style)
m (Installing the SDK: Note about Scribble in SDK 3.2 and later.)
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
''Grzegorz Kraszewski''
 
''Grzegorz Kraszewski''
 +
----
 +
<small>This page in other languages: [[Instalacja SDK (Software Development Kit) i podstawy jego używania|polski]]</small>
  
==Installing SDK==
+
 
 +
==Installing the SDK==
  
 
The official MorphOS SDK provides a complete environment for creating programs
 
The official MorphOS SDK provides a complete environment for creating programs
for MorphOS. It contains following components:
+
for MorphOS. It contains the following components:
  
* MorphOS includes (for MorphOS native API).
+
* MorphOS includes (for the MorphOS native API).
 
* Standard C and C++ library includes.
 
* Standard C and C++ library includes.
 
* MorphOS API documentation and example code.
 
* MorphOS API documentation and example code.
* Two GCC compilers, 2.95.3 and 4.4.4.
+
* Two GCC compilers, 2.95.3 and 4.4.5.
* GCC toolchains (one for every compiler), sets of developer utility programs.
+
* GCC toolchains (one for each compiler), sets of developer utility programs.
* MorphED, a simple programmer's texteditor.
+
* ''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).
 
* Perl scripting language (used by some SDK tools).
  
The first step of instalation is to download the SDK archive from [http://www.morphos.net morphos.net] site, or by clicking [http://www.morphos-team.net/files/sdk-20100617.lha 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 RMB 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 option here is to choose an installation directory. Then there is a time for watching a progress bar...
 
  
After the instalation a system reboot may be needed to update system assigns and paths (the SDK adds some commands to the ''S:user-startup'' script, which is executed at boot).
+
The first step of installation is to download the SDK archive from the [http://www.morphos.net morphos.net] site, or by clicking this [http://www.morphos-team.net/files/sdk-20110916.lha 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 Compiler==
+
==Choosing a Compiler==
  
As mentioned above, the SDK delivers two GCC compilers: an old but trusty 2.95.3 one, and modern 4.4.4. There is a tool named ''GCCSelect'' in the SDK, which allows fast switching between compilers. Just type in shell
+
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
  
 
<tt>GCCSelect 2.95.3</tt>
 
<tt>GCCSelect 2.95.3</tt>
Line 26: Line 31:
 
or
 
or
  
<tt>GCCSelect 4.4.4</tt>
+
<tt>GCCSelect 4.4.5</tt>
 +
 
 +
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.
  
to change the current compiler. ''GCCSelect'' works by making symbolic links to proper version of GCC and its tools, so the compiler is always called as ''gcc'' or ''g++'', regardless of version choosen currently.
 
  
Which one to choose? It depends on code compiled and other constrains. Here is some guidance:
+
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.
 
* 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 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.4.4 is recommended, as the old one simply does not keep up with nowadays standards.
+
* For new projects, especially written in C++, GCC 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, depends on optimizer options).
+
* GCC 4 usually produces faster code (but sometimes also bigger, depending on optimizer options).
* 4.4.4 as relatively new and complex compiler, may contain more bugs than 2.95.3.
+
* 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.
 
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 '''&minus;v''' compiler option, which displays the compiler version and build options:
 +
 +
<tt>gcc -v</tt>
 +
 +
The last line of output shows the GCC version.
  
 
==Standard C and C++ Libraries==
 
==Standard C and C++ Libraries==
  
These standard libraries are parts of C and C++ language specifications respectively. They mainly deliver file and console input/output functions, mathematic functions and string operartions. C++ library provides also a set of basic container classes.
+
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.
  
 
* [http://en.wikipedia.org/wiki/C_standard_library C standard library on Wikipedia]
 
* [http://en.wikipedia.org/wiki/C_standard_library C standard library on Wikipedia]
 
* [http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library C++ standard library on Wikipedia]
 
* [http://en.wikipedia.org/wiki/C%2B%2B_Standard_Library C++ standard library on Wikipedia]
  
There are two ways to access these libraries on MorphOS. The first (and default) one is using a MorphOS [[shared library]] ''ixemul.library''. As the name suggests, this library tries to provide some Unix environment emulation on MorphOS, which, except of standard libraries, includes large part of [http://en.wikipedia.org/wiki/Posix POSIX] standard and some other commonly used functions. ''ixemul.library'' is usually used for porting big projects from Unix/Linux world, for example it is used by GCC itself and many other tools in SDK.
 
  
The second way is to use ''libnix'' (as '''''lib''' '''n'''o '''ix'''emul''). 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 '''-noixemul''' flag to the compiler and the linker. ''libnix'' delivers full C and C++ libraries, but its POSIX implementation is less complete. While an executable compiled with ''libnix'' is usually bigger (because of static linking), the total memory consumption may be lower, as an application using ''ixemul.library'' will load it to memory as a whole, while application linked with ''libnix'' loads whth actually used functions only. On the other hand ''ixemul.library'' may be shared by multiple applications.
+
There are two ways to access these libraries on MorphOS. The first (and default) one is by using a MorphOS [[MorphOS_API_and_Its_Organization|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 [http://en.wikipedia.org/wiki/Posix 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''' '''n'''o '''ix'''emul''). 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 '''&minus;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 for the start, but MorphOS native API provides complete file and console I/O as well as some string manipulation functions and most of mathematic functions. Using native API makes applications faster and smaller in size. On the other hand code using MorphOS API directly is not portable to non-Amiga(like) systems. A '''-nostdlib''' compiler option instructs compiler to not link the code with the standard library.
+
<small>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 '''&minus;nostdlib''' compiler option instructs the compiler to not link the code with the standard library. Note that this requires also writing your own [[Writing Custom Startup Code|custom startup code]].</small>

Latest revision as of 19:47, 9 January 2013

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.