Home   Information   Classes   Download   Usage   Mail List   Requirements   Links   FAQ   Tutorial


Compiling

The Synthesis ToolKit can be used in a variety of ways, depending on your particular needs. Some people choose the classes they need for a particular project and copy those to their working directory. Others create Makefiles that compile project-specific class objects from common src and include directories. And still others like to compile and link to a common library of object files. STK was not designed with one particular style of use in mind.

For specifics on creating Windows applications, see README-Win.txt.

"Realtime" vs. "Non-Realtime"

Most of the Synthesis ToolKit classes are platform independent. That means that they should compile on any reasonably current C++ compiler. The functionality needed for realtime audio and MIDI input/output, as well as realtime control message acquistion, is inherently platform and operating-system (OS) dependent. STK classes that require specific platform/OS support include RtAudio, RtWvOut, RtWvIn, RtDuplex, RtMidi, InetWvIn, InetWvOut, Socket, UdpSocket, TcpServer, TcpClient, Thread, and Mutex. These classes currently can only be compiled on Linux, Macintosh OS X, and Windows systems.

Without the "realtime" classes, it is still possible to read SKINI scorefiles for control input and to read and write to/from a variety of audio file formats (WAV, SND, AIFF, MAT-file, and RAW). If compiling for a "little-endian" host processor, the LITTLE_ENDIAN preprocessor definition should be provided.

Unix Systems:

STK compiles with realtime support on the following flavors of the Unix operating system: Linux, Irix, and Macintosh OS X. Aside from differences in compilers, audio/MIDI APIs, and host endianness, the steps necessary to compile STK programs and classes on these platforms are the same. The following table summarizes these differences.

OS: Realtime Audio/MIDI API: Preprocessor Definition: Library or Framework:
Linux ALSA LINUX_ALSA, __LITTLE_ENDIAN__ asound, pthread
Linux OSS (version 4.0 only, use ALSA for MIDI support) LINUX_OSS, __LINUX_ALSA__, __LITTLE_ENDIAN__ asound, pthread
Linux and Macintosh OS-X Jack UNIX_JACK, __LITTLE_ENDIAN__ asound, pthread, jack
Macintosh OS X CoreAudio MACOSX_CORE pthread, CoreAudio, CoreMIDI, CoreFoundation

The available C++ compilers on any of these systems can vary.

One approach in using STK is to simply copy the class files needed for a particular program into a project directory. Taking the sineosc.cpp example from the previous tutorial chapter, it would be necessary to set up a directory that includes the files sineosc.cpp, the rawwave file sinewave.raw in a subdirectory called rawwaves, and the header and source files for the classes Stk, FileRead, FileWrite, FileWvIn, FileLoop, and FileWvOut. The program could then be compiled on a little-endian system, such as a PC running Linux, using the GNU g++ compiler as follows:

g++ -Wall -D__LITTLE_ENDIAN__ -o sineosc Stk.cpp FileRead.cpp FileWrite.cpp FileWvIn.cpp FileLoop.cpp FileWvOut.cpp sineosc.cpp

Note that the sineosc.cpp example does not make use of realtime audio or MIDI input/output classes. For programs using any of the STK realtime classes mentioned above, it is necessary to specify an audio/MIDI API preprocessor definition and link with the appropriate libraries or frameworks.

When working with a number of different projects that make use of ToolKit classes, the above approach can become cumbersome (especially when trying to synchronize with new STK releases). Most of the STK projects (e.g., demo, effects, ...) contain Makefiles (built by the configure script) that compile project-specific class objects from the distribution src and include directories. This approach makes it relatively easy when upgrading to a new STK release (by making path substitutions in the Makefile or by moving the projects to a similar relative path within the new STK source tree). A Makefile is provided in the projects/examples directory for compiling all the tutorial programs, as well as other example programs. To compile the sineosc.cpp program, for example, one need only type make sineosc from within the projects/examples directory.

Library Use:

The STK distribution provides a Makefile that can be used on Unix systems to build a static library. After unpacking the distribution (tar -xzf stk-4.x.x.tar.gz), run the configure script by typing ./configure from the top level distribution directory (see the INSTALL file in the same directory for more information). Then from within the src directory, type make. After a successful build, you may wish to move the library (libstk.a) and the contents of the include directory to standard library and include search paths on your system. For example, the linux RPM distribution of STK puts the library in /usr/lib/ and the STK header files in /usr/include/stk/.

Assuming the library is located in a standard search path and the header files are located in /usr/include/stk/, the sineosc.cpp example from the previous tutorial chapter can be compiled on a little-endian system using the GNU g++ compiler as follows:

g++ -Wall -D__LITTLE_ENDIAN__ -I/usr/include/stk -o sineosc sineosc.cpp -lstk
The STK namespace.
Definition ADSR.h:6

With the header files in a standard search path, it is possible to modify the #include statements in the sineosc.cpp program as follows:

#include "stk/FileLoop.h"
#include "stk/FileWvOut.h"

and then compile without an explicit include path argument to the compiler:

g++ -Wall -D__LITTLE_ENDIAN__ -o sineosc sineosc.cpp -lstk

[Main tutorial page]   [Next tutorial]


The Synthesis ToolKit in C++ (STK)
©1995--2023 Perry R. Cook and Gary P. Scavone. All Rights Reserved.