What follows here are my notes from the first time that I compiled Csound 5.09 on Mac OS X “Leopard”. Normally, most users should install one of the pre-built binary packages from Sourceforge. But there are some good reasons for building Csound yourself, and in particular on Leopard at the current time (Nov. 2008) because the pre-built binaries are built on 10.4 “Tiger” (which mostly work but see below). My reasons were threefold:
- I wanted to try Chuckk Hubbard’s new Rationale front end and it requires a working Python to Csound interface. The Python interface that comes with the 10.4 Csound packages does not work on 10.5.
- I wanted a Csound with all the “bells and whistles”.
- I am preparing to help build Csound packages for 10.5 Leopard in the future.
I am posting this information in the event that it is useful to anyone else using Mac OS X Leopard. It is not in the form of a tutorial. It is more like a journal of my efforts and the problems that I encountered and how I solved them. I’ve edited them enough so that you will not have to repeat all of my mistakes. However, not everything below will necessarily be self-explanatory. I should hope that anyone who is considering compiling Csound for themselves is resourceful enough to fill-in the blanks.
That said, I am happy to answer questions if you run into trouble. Email me at firstname.lastname@example.org if you need some help. I have not compiled Csound since 2009 so I can no longer offer help on this subject. Thanks for your understanding.
Tuesday October 21, 2008
0. Install latest version of Apple’s XCode development tools (3.1.1)
Make sure to check the UNIX development option and any other optional installs that you want. Disk space required: 2.15 GB.
Update: A newer version of XCode may be out by now. You can download the latest XCode by signing up for a free Apple Developer Connection membership.
1. Downloaded “Csound5.09.0.tar.gz” from Csound’s Sourceforge site.
2. Downloaded the following Csound dependencies in source form:
- fftw-3.1.3.tar.gz Note: only needed if you want Loris opcodes.
- gmm-3.1.tar.gz Note: not actually needed, see below.
- loris-1.3.0.tar.gz Note: only needed if you want Loris opcodes.
The Building Csound page of the Csound manual has links to some of these packages but not all.
Note that at the time I downloaded these packages, I retrieved the latest versions that I could find except for the Loris library. I believe that newer versions of Loris don’t work for building the Csound Loris opcodes. (Also note that the license of Loris is the GPL instead of Csound’s LGPL).
3. Unpacked everything in a new directory (~/Developer/libraries/).
Size of downloads was 62.5MB; size of expanded archives (on disk) was 412.8MB with 42,286 files! (Most of this is boost and gettext).
4. Install SCons:
Open Terminal and navigate to Scons directory (~/Developer/libraries/scons-1.1.0/). Run ‘sudo python setup.py install –symlink-scons’
5. Build and install libsndfile:
cd ~/Developer/libraries/libsndfile-1.0.18pre24e/ ./configure make sudo make install
6. Build and install FLTK libraries:
cd ~/Developer/libraries/fltk-1.1.9/ ./configure --enable-shared --enable-threads make sudo make install
7. Build PortAudio:
cd ~/Developer/libraries/portaudio/ ./configure make
PortAudio docs recommend not doing ‘make install’. See this URL for more information, especially for disabling the quad-architecture build and using the 10.4 SDK: http://www.portaudio.com/trac/wiki/TutorialDir/Compile/MacintoshCoreAudio
Update: I think not installing probably turned out to be a mistake as it caused more trouble later (see below).
Note: The shared libraries are in the portaudio/lib/.libs/ directory. I did ‘ln -s .libs libs’ there to make life easier.
8. Build PortMidi:
cd ~/Developer/libraries/portmidi/ make -f pm_mac/Makefile.osx help [explains targets] make -f pm_mac/Makefile.osx install-with-xcode
These commands build a Universal dynamic library and install it to /usr/local/lib/.
Update: I went back and did these commands when I encountered the porttime.h error (see below) but I don’t think that I should have:
make -f pm_mac/Makefile.osx cleanest [if you built anything previously] make -f pm_mac/Makefile.osx dylib [sudo make -f pm_mac/Makefile.osx install] [did not execute?]
[Time so far: about 5 hours @ 3am Wed]
Wednesday October 22, 2008
I resumed working on building Csound’s dependencies the next afternoon.
9. Build and install Lua:
cd ~/Developer/libraries/lua-5.1.4/ make macosx make test sudo make install lua test/life.lua (for a good time ;)
10. Build and install SWIG:
cd ~/Developer/libraries/swig-1.3.36/ ./configure make sudo make install
11. Build and install fluidsynth:
cd ~/Developer/libraries/fluidsynth-1.0.8/ ./configure --enable-shared [add --enable-double for Csound doubles build?] make sudo make install
Note: I did not follow the instructions in ‘README-OSX’ because I did not want to install Fink, MidiShare, or Jack at this time. They don’t seem to be necessary for use with Csound.
12. Build and install liblo for OSC support:
cd ~/Developer/libraries/liblo-0.25/ ./configure make sudo make install
13. Build and install FFTW 3 (only needed for Loris):
cd ~/Developer/libraries/fftw-3.1.3/ ./configure --enable-shared --enable-portable-binary make sudo make install
14. Copy STK and Loris sources into Csound tree:
cd ~/Developer/libraries/stk-4.3.1/ cp -ipR include rawwaves src ~/Developer/libraries/csound-5.09.0/Opcodes/stk/ cd ~/Developer/libraries/loris-1.3.0/ cp -ipR scripting src ~/Developer/libraries/csound-5.09.0/Opcodes/Loris/
You can copy these folders with the Finder, of course. The folders ‘include’, ‘rawwaves’, etc. are copied — not their contents.
15. Build and install Gmm++ for linear algebra opcodes: (You do not need to perform this step unless you are building with useDouble=1)
cd ~/Developer/libraries/gmm-3.1/ ./configure make sudo make install
Steps 16 & 17 were added after running into trouble building Csound (see below).
16. Build and install libpng:
cd ~/Developer/libraries/libpng-1.2.32/ ./configure make sudo make install
17. Build and install gettext:
cd ~/Developer/libraries/gettext-0.17/ ./configure --without-emacs make sudo make install
Note: gettext installs all sorts of extras that you probably won’t need but I did not see a way to control this in the configure script. The only option that I disabled was Emacs support since I had no idea what that was.
18. Check Csound options and custom.py:
cd ~/Developer/libraries/csound-5.09.0/ scons -h
Modify custom.py as needed. These are the lines for Mac OS X that I arrived at after some experimentation:
elif sys.platform == 'darwin': platform = 'darwin' customCPPPATH.append('/usr/include/malloc') customCPPPATH.append('/Volumes/Data/Users/anthony/Developer/libraries/boost_1_36_0') customCPPPATH.append('/Volumes/Data/Users/anthony/Developer/libraries/portaudio/include') customLIBPATH.append('/Volumes/Data/Users/anthony/Developer/libraries/portaudio/lib/.libs') customCPPPATH.append('/Volumes/Data/Users/anthony/Developer/libraries/portmidi/pm_common') customCPPPATH.append('/Volumes/Data/Users/anthony/Developer/libraries/portmidi/porttime') customCPPPATH.append('/System/Library/Frameworks/Python.Framework/Headers') customLIBS.append('intl') customCXXFLAGS.append('-fabi-version=0')
Also tried running scons -h with all of the options listed below to confirm that it found everything before I started building.
[Time so far: about 10.5 hours]
19. NOW EXECUTE SCONS TO COMPILE CSOUND:
scons dynamicCsoundLibrary=1 buildUtilities=1 buildRelease=1 gcc4opt=7450 usePortAudio=1 usePortMIDI=1 useFLTK=1 buildCsoundVST=0 buildCsoundAC=1 buildCsound5GUI=1 buildLoris=1 useOSC=1 useUDP=1 buildPythonOpcodes=1 buildStkOpcodes=1 useCoreAudio=1 buildTclcsound=1 buildWinsound=1 buildVirtual=1 buildInterfaces=1 buildJavaWrapper=1 buildOSXGUI=1 buildCSEditor=1 buildNewParser=0 useGettext=1 buildImageOpcodes=1
IMPORTANT: Add a ‘sudo’ in front of this command or else Csound.framework cannot be created in /Library/Frameworks. Obviously, this command will overwrite any existing Csound framework in that location. (You can remove buildRelease=1 instead if not installing and then you do not need ‘sudo’).
NOTE: The gcc4opt=7450 option optimizes Csound for a PowerPC G4 processor. You should adjust this option or remove it if your computer has a different processor.
NOTE: I experienced the following error at first:
Checking for C header file stdio.h... no *** Failed to compile a simple test program. The compiler is *** possibly not set up correctly, or is used with invalid flags. *** Check config.log to find out more about the error.
It turned out to be a result of the following erroneous custom path setting:
Appended paths cannot be a file, they must be a directory. (I did not intend to specify the file instead of the directory, but it got in there somehow).
THEN, this error while compiling:
H/text.h:111:21: error: libintl.h: No such file or directory
because GNU GetText was not installed yet. (Downloaded and added step 17).
NEXT, this error while linking CsoundLib:
Undefined symbols: "_libintl_dgettext", referenced from: _csoundLocalizeString in getstring.os ld: symbol(s) not found
Adding customLIBS.append(‘intl’) to custom.py fixes this.
g++ -o Opcodes/chua/ChuaOscillator.os -c -fno-rtti -fexceptions -fabi-version=0 -O3 -mcpu=7450 -mtune=7450 -ftree-vectorize -ffast-math -DGNU_GETTEXT -g -fomit-frame-pointer -DMACOSX -DPIPES -fPIC -DHAVE_LIBSNDFILE=1016 -DHAVE_FLTK -DSDFT -DHAVE_FCNTL_H -DHAVE_UNISTD_H -DHAVE_STDINT_H -DHAVE_SYS_TIME_H -DHAVE_SYS_TYPES_H -DHAVE_TERMIOS_H -DHAVE_SOCKETS -DHAVE_DIRENT_H -I. -IH -I/usr/include/malloc -I/Volumes/Data/Users/anthony/Developer/libraries/boost_1_36_0 -I/Volumes/Data/Users/anthony/Developer/libraries/portaudio/include -I/Volumes/Data/Users/anthony/Developer/libraries/portmidi/pm_common -I/System/Library/Frameworks/Python.Framework/Headers -I/usr/local/include Opcodes/chua/ChuaOscillator.cpp /Volumes/Data/Users/anthony/Developer/libraries/boost_1_36_0/boost/exception/exception.hpp: In member function 'const char* boost::exception::_diagnostic_information(const char*) const': /Volumes/Data/Users/anthony/Developer/libraries/boost_1_36_0/boost/exception/exception.hpp:74: error: cannot use typeid with -fno-rtti /Volumes/Data/Users/anthony/Developer/libraries/boost_1_36_0/boost/exception/exception.hpp:81: error: cannot use typeid with -fno-rtti
Problem is on line 1161 of SConstruct:
if getPlatform() == 'darwin': pluginEnvironment.Append(LINKFLAGS = Split(''' -framework CoreMidi -framework CoreFoundation -framework CoreAudio ''')) # pluginEnvironment.Append(LINKFLAGS = ['-dynamiclib']) pluginEnvironment['SHLIBSUFFIX'] = '.dylib' pluginEnvironment.Prepend(CXXFLAGS = "-fno-rtti")
HACK: Commented out that last line to get it to compile for now.
Followed by template problems (?) in linear_algebra.cpp:
Opcodes/linear_algebra.cpp: In member function 'int la_i_qr_eigen_mr_t::init(CSOUND*)': Opcodes/linear_algebra.cpp:4117: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: /usr/local/include/gmm/gmm_dense_qr.h:552: note: candidate 1: void gmm::implicit_qr_algorithm(const MAT1&, const VECT&, const MAT2&, typename gmm::number_traits::value_type>::magnitude_type, bool) [with MAT1 = gmm::dense_matrix, VECT = std::vector >, MAT2 = double] /usr/local/include/gmm/gmm_dense_qr.h:586: note: candidate 2: void gmm::implicit_qr_algorithm(const MAT1&, VECT&, typename gmm::number_traits::value_type>::magnitude_type) [with MAT1 = gmm::dense_matrix, VECT = std::vector >] Opcodes/linear_algebra.cpp: In member function 'int la_k_qr_eigen_mr_t::kontrol(CSOUND*)':
HACK: Commented out this target in SConstruct for now.
Update: Michael Gogins has informed me that the linear algebra opcodes only work when compiling Csound to use double-precision floating-point numbers. SConstruct should be fixed to reflect this.
InOut/pmidi.c:32:22: error: porttime.h: No such file or directory InOut/pmidi.c: In function 'start_portmidi': InOut/pmidi.c:169: error: 'ptNoError' undeclared (first use in this function) InOut/pmidi.c:169: error: (Each undeclared identifier is reported only once InOut/pmidi.c:169: error: for each function it appears in.) scons: *** [InOut/pmidi.os] Error 1
Needed to add location of porttime.h to custom.py:
ld: library not found for -lcsnd collect2: ld returned 1 exit status scons: *** [counterpoint] Error 1
HACK: Do ‘ln -s lib_csnd.dylib libcsnd.dylib’ then continue.
Thu Oct 23 2008 2:28 AM: scons: done building targets. ^_^
Fiona:csound-5.09.0 anthony$ ./csound -z dyld: Library not loaded: /usr/local/lib/libportaudio.2.dylib Referenced from: /Volumes/Data/Users/anthony/Developer/libraries/csound-5.09.0/./csound Reason: image not found Trace/BPT trap
DOH!: libportaudio.2.dylib is not in /usr/local/lib because we didn’t install.
cd ~/Developer/libraries/portaudio/ sudo make install
Fiona:csound-5.09.0 anthony$ ./csound -z PortMIDI real time MIDI plugin for Csound PortAudio real-time audio module for Csound virtual_keyboard real time MIDI plugin for Csound 0dBFS level = 32768.0 Csound version 5.09 (float samples) Oct 23 2008 libsndfile-1.0.18pre24e Error: define environment variable RAWWAVE_PATH (points to rawwaves directory) to use STK opcodes. rtaudio: PortAudio module enabled ... using callback interface rtmidi: PortMIDI module enabled 1380 opcodes ATSadd ATSaddnz ATSbufread ATScross ATSinfo ATSinterpread ATSpartialtap ATSread ATSreadnz ATSsinnoi FLbox FLbutBank ...
And, finally …
Fiona:csound-5.09.0 anthony$ ./csound examples/trappedrt.csd
… IT WORKS! (about 3:20 AM Thu)
Summary of Build Effort
Total Time: about 13 hours
libraries/csound-5.09.0/ 127.0 MB 2,256 files libraries/ 635.9 MB 46,673 files /Library/Frameworks/Csound... 4.0 MB 85 files /usr/local/ 39.8 MB 3,315 files /Developer 2201.6 MB 47,706 files ---------- Total Disk Space Used: 2881.3 MB
CsoundAC.py CsoundLib CsoundLib.framework _CsoundAC.so _csnd.so _loris.so atsa counterpoint cs csb64enc cseditor csladspa.so csnd.jar csnd.py csound csound5gui cstclsh cswish cvanal dnoise envext extract extractor het_export het_import hetro libCsoundAC.a lib_csnd.dylib lib_jcsound.jnilib libambicode1.dylib libampmidid.dylib libbabo.dylib libbarmodel.dylib libchua.dylib libcompress.dylib libcontrol.dylib libcs_date.dylib libcs_pan2.dylib libcs_pvs_ops.dylib libcsnd.dylib libeqfil.dylib libfluidOpcodes.dylib libftest.dylib libgabnew.dylib libgrain4.dylib libharmon.dylib libhrtferX.dylib libhrtfnew.dylib libimage.dylib libloris.dylib liblorisbase.a libloscilx.dylib libminmax.dylib libmixer.dylib libmodal4.dylib libmutexops.dylib libosc.dylib libpartikkel.dylib libphisem.dylib libphysmod.dylib libpitch.dylib libpmidi.dylib libptrack.dylib libpvoc.dylib libpvsbuffer.dylib libpy.dylib librtcoreaudio.dylib librtpa.dylib libscansyn.dylib libscoreline.dylib libsfont.dylib libshape.dylib libstackops.dylib libstdopcod.dylib libstdutil.dylib libstk.dylib libstk_base.a libsystem_call.dylib libudprecv.dylib libudpsend.dylib libugakbari.dylib libvaops.dylib libvbap.dylib libvirtual.dylib libvosim.dylib libwidgets.dylib loris.py lpanal lpc_export lpc_import makecsd mixer pv_export pv_import pvanal pvlook scale scot scsort sdif2ad sndinfo srconv tclcsound.dylib winsound frontends/winsound/Winsound.app frontends/OSX/build/Deployment/Csound 5.app frontends/fltk_gui/Csound5GUI.app
Installing the Rest of the Binaries
Thursday, Oct 23 2008, Afternoon
The Csound build script did not install anything except the basic Csound.framework and plugin libraries. Command-line exectuables, Mac OS X applications, language wrappers, and extras such as CsoundAC and TclCsound remain in the build directory only.
I modified the install.py script (which is for Linux) to have some control over what is installed, making it more usable for OS X (though not ideal).
I also created a symlink for python2.5 site packages to mirror the one that existed for Python 2.3 so that the install script would place those files in the correct place.
sudo ln -s /Library/Python/2.5/site-packages /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages
NOTE: I would not try running the install.py script that comes with Csound on OS X without modifying it.
Here is my modified install.py. Rename the file after you download it.
Fiona:csound-5.09.0 anthony$ sudo ./install.py Password: Csound5 Linux installer by Istvan Varga === Installing executables === /usr/local/bin/csound /usr/local/bin/csound5gui /usr/local/bin/winsound /usr/local/bin/cstclsh /usr/local/bin/cswish /usr/local/bin/cseditor /usr/local/bin/cvanal /usr/local/bin/dnoise /usr/local/bin/envext /usr/local/bin/extractor /usr/local/bin/het_export /usr/local/bin/het_import /usr/local/bin/hetro /usr/local/bin/lpanal /usr/local/bin/lpc_export /usr/local/bin/lpc_import /usr/local/bin/mixer /usr/local/bin/pvanal /usr/local/bin/pv_export /usr/local/bin/pv_import /usr/local/bin/pvlook /usr/local/bin/scale /usr/local/bin/sndinfo /usr/local/bin/srconv /usr/local/bin/scsort /usr/local/bin/extract /usr/local/bin/cs /usr/local/bin/csb64enc /usr/local/bin/makecsd /usr/local/bin/scot /usr/local/bin/brkpt /usr/local/bin/linseg /usr/local/bin/tabdes === Installing libraries === === Installing language interfaces === /usr/lib/python2.5/site-packages/csnd.py /usr/lib/python2.5/site-packages/loris.py /usr/lib/python2.5/site-packages/CsoundAC.py /usr/lib/python2.5/site-packages/_csnd.so /usr/lib/python2.5/site-packages/_loris.so /usr/lib/python2.5/site-packages/_CsoundAC.so /usr/local/lib/csound/java/csnd.jar === Installing uninstall script === /usr/local/bin/uninstall-csound5 === Installing MD5 checksums === /usr/local/csound5-2008-10-23.md5sums Csound installation has been successfully completed. Before running Csound, make sure that the following environment variables are set: OPCODEDIR=/usr/local/lib/csound/plugins CSSTRNGS=/usr/local/share/locale Csound can be uninstalled by running /usr/local/bin/uninstall-csound5
This still did not properly install everything and I had to do some more copies by hand later (see below).
Also, I dragged these apps to the /Applications folder:
- frontends/OSX/build/Deployment/Csound 5.app
All of these applications launch and the latter two work pretty well. Winsound had problems when playing a CSD (“No such directory”). Csound 5 CSDPlayer (the java jar) crashed when I tried to play a CSD.
Getting Rationale to Run
Finally to the goal of this entire exercise — to be able to load the Python interface library ‘csnd’ and run ‘rationale’ by Chuckk Hubbard. A simple ‘import csnd’ still fails in Python:
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import csnd Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.5/site-packages/csnd.py", line 7, in import _csnd ImportError: dlopen(/Library/Python/2.5/site-packages/_csnd.so, 2): Library not loaded: /Library/Frameworks/CsoundLib.framework/Versions/5.1/lib_csnd.dylib Referenced from: /Library/Python/2.5/site-packages/_csnd.so Reason: image not found
So I copied these files to CsoundLib.framework/Versions/5.1/:
tclcsound.dylib lib_jcsound.jnilib lib_csnd.dylib
‘import csnd’ now succeeds, so …
Fiona:rationale anthony$ python rationale.py Traceback (most recent call last): File "rationale.py", line 2502, in root = tk.Tk() File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-tk/Tix.py", line 210, in __init__ self.tk.eval('package require Tix') _tkinter.TclError: can't find package Tix
Curses! /System/Library/Tcl seems to have no Tix package.
Downloading and installing TclTkAquaBI-126.96.36.199.dmg from the Tcl/Tk Aqua project on Sourceforge provides a usable Tix library for Python.
Finally, Rationale runs!! Yay!