Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to compile VAMP Plugins to iOS ARMV7
    text
    copied!<p><a href="http://vamp-plugins.org/" rel="noreferrer">VAMP</a> Plugins by Queen Mary University of London is an amazing collection of BSD licensed software. All these plugins are at the basis of the <a href="http://www.sonicvisualiser.org/" rel="noreferrer">Sonic Visualizer</a> software <a href="https://code.soundsoftware.ac.uk/projects/vamp-plugin-sdk" rel="noreferrer">A plug Sdk</a> to build plugins is available as well.</p> <p>You can build the plugins for OSX / Linux / Win32 targets.</p> <p>Queen Mart University explain well <a href="http://vamp-plugins.org/develop.html" rel="noreferrer">here</a> the plugin architecture and how to build for different platforms specified above.</p> <p>A Java version, jVamp is available as well. A Python wrapper also.</p> <p><strong>But, how to build for the iOS platform ?</strong></p> <p>So, I tried porting the Makefile to the iOS.</p> <p>First I changed the file</p> <pre><code>build/osx/Makefile.osx </code></pre> <p>in this way:</p> <pre><code>CFLAGS := -O3 -ftree-vectorize -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -arch x86_64 -I../vamp-plugin-sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/ -DUSE_PTHREADS CXXFLAGS := $(CFLAGS) LDFLAGS := -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -arch x86_64 -lqm-dsp ../vamp-plugin-sdk/libvamp-sdk.a -framework Accelerate -lpthread -exported_symbols_list=vamp-plugin.list -install_name qm-vamp-plugins.a PLUGIN_EXT := .a include build/general/Makefile.inc </code></pre> <p>Then build</p> <pre><code>macbookproloreto:qm-vamp-plugins loreto$ make -f build/osx/Makefile.osx cc -O3 -ftree-vectorize -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -arch x86_64 -I../vamp-plugin-sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/ -DUSE_PTHREADS -I. -I../qm-dsp -c -o g2cstubs.o g2cstubs.c c++ -O3 -ftree-vectorize -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -arch x86_64 -I../vamp-plugin-sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/ -DUSE_PTHREADS -I. -I../qm-dsp -c -o plugins/AdaptiveSpectrogram.o plugins/AdaptiveSpectrogram.cpp In file included from plugins/AdaptiveSpectrogram.cpp:15: In file included from plugins/AdaptiveSpectrogram.h:18: In file included from ../vamp-plugin-sdk/vamp-sdk/Plugin.h:40: In file included from /usr/bin/../lib/c++/v1/string:430: In file included from /usr/bin/../lib/c++/v1/iosfwd:90: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/wchar.h:70: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/_types.h:27: In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/sys/_types.h:32: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/sys/cdefs.h:655:2: **error: Unsupported architecture #error Unsupported architecture ^** </code></pre> <p>The first issue here is that there is a unsupported architecture.</p> <p>So the plugins depends on the SDK I had to build that one first:</p> <pre><code>cd /Users/loreto/Projects/AUDIO/VAMP/vamp-plugin-sdk make -f build/Makefile.osx </code></pre> <p>Different errors occurred since I had no <a href="http://www.vorbis.com/" rel="noreferrer">OGG/VORBIS</a> library and no LOGG library. So I slightly modified the Makefile.osx removing these dependencies in the HOST_LIB flags. I had to keep <a href="http://www.mega-nerd.com/libsndfile/" rel="noreferrer">libsndfile</a> anyway:</p> <pre><code>HOST_LIBS = ./libvamp-hostsdk.a -L../10.8/inst/lib -lsndfile -ldl </code></pre> <p>So I was able to build the static libraries here:</p> <pre><code>macbookproloreto:vamp-plugin-sdk loreto$ ls -l *.a -rw-r--r-- 1 loreto staff 709840 17 Ott 23:56 libvamp-hostsdk.a -rw-r--r-- 1 loreto staff 183720 17 Ott 23:56 libvamp-sdk.a </code></pre> <p>Of course these static libs are targeted to arch x86_64 so I need to add armv7 arch:</p> <pre><code>ARCHFLAGS = -mmacosx-version-min=$(MINVERSION) -arch x86_64 -arch armv7 </code></pre> <p>Then make clean and compile again</p> <pre><code>macbookproloreto:vamp-plugin-sdk loreto$ make -f build/Makefile.osx clean macbookproloreto:vamp-plugin-sdk loreto$ make -f build/Makefile.osx c++ -mmacosx-version-min=10.8 -arch x86_64 -arch armv7 -O2 -Wall -I. -I../10.8/inst/include -fPIC -c -o src/vamp-sdk/PluginAdapter.o src/vamp-sdk/PluginAdapter.cpp In file included from src/vamp-sdk/PluginAdapter.cpp:37: In file included from ./vamp-sdk/PluginAdapter.h:40: In file included from /usr/include/c++/4.2.1/map:64: In file included from /usr/include/c++/4.2.1/bits/stl_tree.h:68: In file included from /usr/include/c++/4.2.1/bits/stl_algobase.h:65: In file included from /usr/include/c++/4.2.1/bits/c++config.h:41: In file included from /usr/include/c++/4.2.1/bits/os_defines.h:61: In file included from /usr/include/unistd.h:71: In file included from /usr/include/_types.h:27: In file included from /usr/include/sys/_types.h:33: /usr/include/machine/_types.h:34:10: fatal error: 'arm/_types.h' file not found #include "arm/_types.h" ^ 1 error generated. make: *** [src/vamp-sdk/PluginAdapter.o] Error 1 </code></pre> <p>Type definitions for arm was not found! The problem here is that the right path was</p> <pre><code>/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/arm/_types.h </code></pre> <p>Ok let's fix this in the Makefile.osx again:</p> <pre><code>ARCHFLAGS = -mmacosx-version-min=$(MINVERSION) -arch armv7 CFLAGS = $(ARCHFLAGS) -fPIC --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -isystem /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/ CXXFLAGS = $(ARCHFLAGS) -O2 -Wall -I. -fPIC CPPFLAGS ="-pipe -no-cpp-precomp -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/" -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk </code></pre> <p>then make the static targets:</p> <pre><code>make -f build/Makefile.osx sdkstatic </code></pre> <p><strong>Wow it worked! I have a vamp host sdk .a for iOS!</strong> (I suppose to have let's say)</p> <pre><code>macbookproloreto:vamp-plugin-sdk loreto$ ls -l *.a -rw-r--r-- 1 loreto staff 301176 18 Ott 00:35 libvamp-hostsdk.a -rw-r--r-- 1 loreto staff 76024 18 Ott 00:35 libvamp-sdk.a </code></pre> <p>Ok but let's check with otool, since you never know:</p> <pre><code>macbookproloreto:vamp-plugin-sdk loreto$ otool -hv libvamp-sdk.a Archive : libvamp-sdk.a libvamp-sdk.a(PluginAdapter.o): Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC ARM V7 0x00 OBJECT 4 1128 SUBSECTIONS_VIA_SYMBOLS libvamp-sdk.a(RealTime.o): Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC ARM V7 0x00 OBJECT 4 1060 SUBSECTIONS_VIA_SYMBOLS libvamp-sdk.a(FFT.o): Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC ARM V7 0x00 OBJECT 4 584 SUBSECTIONS_VIA_SYMBOLS libvamp-sdk.a(acsymbols.o): Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC ARM V7 0x00 OBJECT 3 500 SUBSECTIONS_VIA_SYMBOLS </code></pre> <p>Ok, that's the armv7 architecture.</p> <p>Now, back to the plugins sdk again and change the</p> <pre><code>build/osx/Makefile.osx </code></pre> <p>as follows:</p> <pre><code>CFLAGS := -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/ -DUSE_PTHREADS CXXFLAGS := $(CFLAGS) include build/general/Makefile.inc </code></pre> <p>Ok back again and make:</p> <pre><code>macbookproloreto:dsp loreto$ make -f build/osx/Makefile.osx </code></pre> <p>Boom! Another problem:</p> <pre><code>/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/ -DUSE_PTHREADS -I. -c -o dsp/wavelet/Wavelet.o dsp/wavelet/Wavelet.cpp cc -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/ -DUSE_PTHREADS -I. -c -o hmm/hmm.o hmm/hmm.c hmm/hmm.c:21:10: fatal error: 'clapack.h' file not found #include &lt;clapack.h&gt; /* LAPACK for matrix inversion */ ^ 1 error generated. make: *** [hmm/hmm.o] Error 1 macbookproloreto:dsp loreto$ vi build/osx/Makefile.osx </code></pre> <p>LAPACK not found.</p> <p>But as for Apple Docs <a href="https://developer.apple.com/library/ios/releasenotes/General/iPhone40APIDiffs/" rel="noreferrer">here</a>, Apple introduced LAPACK in the Accelerate.frameworks since iOS4.0!</p> <p>In fact clapack.h is here: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/clapack.h</p> <p>So let's add this somewhere in the ../dsp/build/Makefile.osx</p> <pre><code>CFLAGS := -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/ -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/ -DUSE_PTHREADS </code></pre> <p>And now let's make it again, but let me check the arch:</p> <pre><code>macbookproloreto:dsp loreto$ otool -hv libqm-dsp.a Archive : libqm-dsp.a libqm-dsp.a(Pitch.o): Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC ARM V7 0x00 OBJECT 4 516 SUBSECTIONS_VIA_SYMBOLS libqm-dsp.a(Chromagram.o): Mach header </code></pre> <p>Sound good! One level back in the plugins folder now and make</p> <pre><code>In file included from plugins/AdaptiveSpectrogram.cpp:15: plugins/AdaptiveSpectrogram.h:22:10: fatal error: 'dsp/transforms/FFT.h' file not found #include &lt;dsp/transforms/FFT.h&gt; ^ 1 error generated. </code></pre> <p>Uhm ok the dsp/ misses the tranforms folder - gosh!</p> <p>Another error:</p> <pre><code>clang: error: invalid argument '-install_name qm-vamp-plugins.a' only allowed with '-dynamiclib' make: *** [qm-vamp-plugins.a] Error 1 </code></pre> <p>Let's fix again the Makefile.osx:</p> <pre><code>CFLAGS := -O3 -ftree-vectorize -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -arch armv7 -I../vamp-plugin-sdk -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/ -DUSE_PTHREADS CXXFLAGS := $(CFLAGS) LDFLAGS := -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -arch armv7 -lqm-dsp ../vamp-plugin-sdk/libvamp-sdk.a -framework Accelerate -lpthread </code></pre> <p>Ok, now the error is architecture undefined symbol errors: to long look at the gist <a href="https://gist.github.com/loretoparisi/7034060" rel="noreferrer">here</a> like:</p> <pre><code> "std::cerr", referenced from: "typeinfo for std::istream", referenced from: "std::ostream::put(char)"" std::ostream::operator&lt;&lt;(int)", </code></pre> <p>This reminds me to the <a href="http://www.boost.org/" rel="noreferrer">boost</a> C++ libraries!</p> <p>So I need to get boost, compile for iOS then include it in the Makefile and it should work, isn't it ? This could take long...</p> <p>So do this by now</p> <pre><code>macbookproloreto:vamp-plugin-sdk loreto$ echo $'\360\237\215\272' </code></pre> <p><img src="https://i.stack.imgur.com/ff3kp.png" alt="http://i.stack.imgur.com/ff3kp.png"></p> <p>After getting boost as iOS framework distribution from <a href="https://github.com/FWKamil/boost-ios" rel="noreferrer">here</a> and adding</p> <p>-I/Users/loreto/Projects/AUDIO/LIBS/boost-ios/Dist/boost.framework/Headers/ </p> <p>I have the same error...uhm I suppose I'm missing the standard C++ library here!</p> <pre><code>macbookproloreto:Headers loreto$ locate libc++.dylib | grep iPhoneOS7.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/lib/libc++.dylib </code></pre> <p>bingo!</p> <p>So</p> <pre><code>-I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/lib/libc++.dylib </code></pre> <p>Error again (doh) !</p> <p>Tried with no success</p> <pre><code> -I/usr/lib/libstdc++.dylib -lstdc++ </code></pre> <p>Stucked on a very simple linking issue.</p> <p>Again.</p> <pre><code>macbookproloreto:vamp-plugin-sdk loreto$ echo $'\360\237\215\272' </code></pre> <p><img src="https://i.stack.imgur.com/ff3kp.png" alt="http://i.stack.imgur.com/ff3kp.png"></p> <p>The most interesting part of the error is the first static library being compiled:</p> <pre><code>make -f build/osx/Makefile.osx c++ -o qm-vamp-plugins.a g2cstubs.o plugins/AdaptiveSpectrogram.o plugins/BarBeatTrack.o plugins/BeatTrack.o plugins/DWT.o plugins/OnsetDetect.o plugins/ChromagramPlugin.o plugins/ConstantQSpectrogram.o plugins/KeyDetect.o plugins/MFCCPlugin.o plugins/SegmenterPlugin.o plugins/SimilarityPlugin.o plugins/TonalChangeDetect.o plugins/Transcription.o libmain.o -L../qm-dsp -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -arch armv7 -lqm-dsp ../vamp-plugin-sdk/libvamp-sdk.a -framework Accelerate -lpthread Undefined symbols for architecture armv7: "std::basic_stringbuf&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::str() const", referenced from: _VampPlugin::Vamp::RealTime::toString() const in libvamp-sdk.a(RealTime.o) _VampPlugin::Vamp::RealTime::toText(bool) const in libvamp-sdk.a(RealTime.o) "std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;::widen(char) const", referenced from: _VampPlugin::Vamp::PluginAdapterBase::Impl::getDescriptor() in libvamp-sdk.a(PluginAdapter.o) </code></pre> <p>Here we can see that one of the static library compiled does not contain the right architecture.</p> <p>I have two static libraries here:</p> <pre><code>lqm-dsp ../vamp-plugin-sdk/libvamp-sdk.a </code></pre> <p>If I run otool on that I can see that the cpu time is ARM7 for both of them:</p> <pre><code>macbookproloreto:qm-vamp-plugins loreto$ otool -hv ../vamp-plugin-sdk/libvamp-sdk.a Archive : ../vamp-plugin-sdk/libvamp-sdk.a ../vamp-plugin-sdk/libvamp-sdk.a(PluginAdapter.o): Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags MH_MAGIC ARM V7 0x00 OBJECT 4 1128 SUBSECTIONS_VIA_SYMBOLS </code></pre> <p>So what's the matter with Developer/SDKs/iPhoneOS7.0.sdk/usr/lib/libc++.dylib ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload