essentia icon indicating copy to clipboard operation
essentia copied to clipboard

Essential Cross compiling iOS

Open iOSzhangkai opened this issue 8 years ago • 25 comments

I cross compile iOS practices: 1.

brew, install, yasm, cmake, WGet, packaging/build_3rdparty_static_debian.sh

Building, lightweight, Essentia, with, reduced, dependencies:./waf, configure, --lightweight=, --fft=ACCELERATE

3.iOS:

./waf, configure, --cross-compile-ios, --lightweight=, --fft=ACCELERATE, --build-static

Is that correct? I have libessentia.a. in the /essentia-master/build/src directory, but how does this libessentia.a static package work in iOS's Xcode project?

iOSzhangkai avatar Jul 05 '17 03:07 iOSzhangkai

I answered this in your other message.

carthach avatar Jul 05 '17 11:07 carthach

Excuse me. You gave me this project. I saw it on someone else's problem yesterday, but after the download of this project, there was no file in the iOS directory; Cross compilation of iOS official documents involving less, but there is no system compiler tutorial, do you have any blog or document you want to study, I hope you can let me learn, thank you

iOSzhangkai avatar Jul 06 '17 02:07 iOSzhangkai

I follow the document on the iOS cross compiler command, libessentia.a file in the /build/src directory, the libessentia.a package is generally with a static.H file, is my error allocation process, not playing.H files, or what reason, I hope you can help me to answer, thank you [PS: I'm not too good the English, if there is no clear expression, please forgive]

iOSzhangkai avatar Jul 06 '17 06:07 iOSzhangkai

Sorry I can't really understand your problem and I am not an iOS developer so I can't really help any more.

You will need to search Google for information on using C++ libraries with iOS.

For example here's a tutorial I found: https://www.sitepoint.com/using-c-and-c-in-an-ios-app-with-objective-c/

Good luck!

carthach avatar Jul 06 '17 07:07 carthach

So I think I have hit the same issue as him. I've got the essentia complied with the flags outlined in the guide. But where are the header files that we need to use this library? When using a static library in Xcode, there are some header files which we can use to interface with the library from objective-c. I saw somewhere else on that these are located in /user/local/include/essentia however I do not see the essentia directory here. Is there an additional flag needed to generate these?

willrevl avatar Aug 04 '17 10:08 willrevl

Well remember to set the prefix flag --prefix= to wherever you want.

After you compile don't forget to run ./waf install. This will install into the location and will install headers into

<LOCATION>/include

and the library into:

<LOCATION>/lib

carthach avatar Aug 04 '17 13:08 carthach

@carthach thanks so much for the prompt response. I found the headers!

I'm really close, my problem now is that I can't get Xcode to see the c++ stl. argh!

willrevl avatar Aug 05 '17 02:08 willrevl

^ my issue there was that I needed to include essential from a .mm file so that Xcode would recognize it as objective-c++

willrevl avatar Aug 05 '17 09:08 willrevl

Might need to include libstdc++ as well, I'm not sure. I'm not an iOS programmer I'm afraid! I just compiled it for use with JUCE which allows you to program directly for iOS using C++.

carthach avatar Aug 05 '17 09:08 carthach

Xcode already knows about libstdc++, it just needs to interpret the file you are using as objective-c++ to know it needs to use it.

willrevl avatar Aug 06 '17 08:08 willrevl

So I just tried to sort of copy the example from here: https://github.com/MTG/essentia/blob/master/src/examples/onset_detector.cpp

but I got this error message: libc++abi.dylib: terminating with uncaught exception of type essentia::EssentiaException: Identifier 'MonoLoader' not found in registry...

Are the examples working with an older version of essential or something? Or might I be doing something horribly wrong?

willrevl avatar Aug 06 '17 09:08 willrevl

The MonoLoader algorithm is missing if you compiled essentia without ffmpeg dependency. See the output of wad configure or check build/config.log for more details.

On Aug 6, 2017 11:27, "willrevl" [email protected] wrote:

So I just tried to sort of copy the example from here: https://github.com/MTG/essentia/blob/master/src/ examples/onset_detector.cpp

but I got this error message: libc++abi.dylib: terminating with uncaught exception of type essentia::EssentiaException: Identifier 'MonoLoader' not found in registry...

Are the examples working with an older version of essential or something? Or might I be doing something horribly wrong?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MTG/essentia/issues/620#issuecomment-320495791, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZARAX4f2LViJjDkDxw5YAEYAX67E4aks5sVYcegaJpZM4ON0ga .

dbogdanov avatar Aug 06 '17 09:08 dbogdanov

Yes, seems this is the default for using on iOS, is there an alternative to the MonoLoader algorithm for getting audio data in?

willrevl avatar Aug 06 '17 09:08 willrevl

I suppose just read it with audio units then convert to a vector<Real> and that should work.

willrevl avatar Aug 06 '17 10:08 willrevl

Another question, my project already depends on ffmpeg, is it possible to do the iOS compile, but include the ffmpeg dependency?

willrevl avatar Aug 06 '17 10:08 willrevl

You can specify dependencies to include using the --lightweight flag. For example, --lightweight=libav will include ffmpeg (build script will search for it using pkg-config)

On Aug 6, 2017 12:02, "willrevl" [email protected] wrote:

Another question, my project already depends on ffmpeg, is it possible to do the iOS compile, but include the ffmpeg dependency?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MTG/essentia/issues/620#issuecomment-320497264, or mute the thread https://github.com/notifications/unsubscribe-auth/AAZARI74b9fxCvdDMxWJK1OzZBNInEh4ks5sVY8qgaJpZM4ON0ga .

dbogdanov avatar Aug 06 '17 20:08 dbogdanov

OK, so i've tried building with this flag. However now I am getting this:

./waf configure --cross-compile-ios --lightweight=libav --fft=ACCELERATE --build-static
...
- FFmpeg / libav detected!
- libsamplerate seems to be missing.
  The following algorithms will be ignored: ['Resample', 'MonoLoader', 'EqloudLoader', 'EasyLoader']

willrevl avatar Aug 09 '17 01:08 willrevl

When I check for libsamplerate: [Revl] essentia$ brew install libsamplerate Warning: libsamplerate 0.1.9 is already installed

willrevl avatar Aug 09 '17 01:08 willrevl

So I added libsamplerate and the build appeared to include the 'MonoLoader' algorithm. However, now i'm getting:

Undefined symbols for architecture arm64:
  "_src_reset", referenced from:
      essentia::streaming::Resample::reset() in libessentia.a(resample.cpp.1.o)
  "_src_simple", referenced from:
      essentia::standard::Resample::compute() in libessentia.a(resample.cpp.1.o)
  "_src_process", referenced from:
      essentia::streaming::Resample::process() in libessentia.a(resample.cpp.1.o)
  "_src_delete", referenced from:
      essentia::streaming::Resample::~Resample() in libessentia.a(resample.cpp.1.o)
      essentia::streaming::Resample::configure() in libessentia.a(resample.cpp.1.o)
  "_src_new", referenced from:
      essentia::streaming::Resample::configure() in libessentia.a(resample.cpp.1.o)
  "_src_strerror", referenced from:
      essentia::standard::Resample::compute() in libessentia.a(resample.cpp.1.o)
      essentia::streaming::Resample::process() in libessentia.a(resample.cpp.1.o)
      essentia::streaming::Resample::reset() in libessentia.a(resample.cpp.1.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

willrevl avatar Aug 09 '17 02:08 willrevl

I'm assuming I need to compile libsamplerate, but I am stuck at getting this compiled for arm64

willrevl avatar Aug 09 '17 03:08 willrevl

for the next guy, finally got this working steps where:

  1. Compile essentia ./waf configure --cross-compile-ios —lightweight=libav,libsamplerate --fft=ACCELERATE --build-static
  2. Compile FFMPEG with libavresample
  3. clone https://github.com/erikd/libsamplerate, drag files from source into a new Xcode project of type static library / framework and compile. Use the resulting .a file.

This will allow the MonoLoader algorithm and so examples can be copied more easily:

https://github.com/MTG/essentia/blob/master/src/examples/

willrevl avatar Aug 09 '17 04:08 willrevl

Nice work Will!

carthach avatar Aug 09 '17 08:08 carthach

I hope I am posting this in the right place, but it looks like this thread is relevant to what I am struggling with. I am currently working on an iOS app in Swift and I have been trying to understand how I can cross compile into iOS and integrate the library into my Swift project. I am new to Essentia, iOS, Swift, and haven't worked with C++ in years, so please excuse me if I seem a little slow on the uptake here.

I successfully ran the ./waf configure --cross-compile-ios --lightweight= --fft=ACCELERATE --build-static command. It produced a folder called "build" with the following contents:

  • .lock-waf_darwin_build
  • .wafpickle-darwin-34015984-98
  • c4che (folder)
  • config.log (folder)
  • essentia.pc
  • src (folder)

Inside the src folder I find the following:

  • 3rdparty (folder)
  • algorithms (folder)
  • essentia (folder)
  • libessentia.a

It's my understanding that libessentia.a is the compiled C++ library which includes all the object files in the other folders. After reading this article it seems that I would need to include this file in the Build Phases section of my project's configuration file. It also seems that I would need the header (.h) files for Essentia. Now, I ran the ./waf install command, and I found some header files under /usr/local/include/essentia, however it doesn't look like they are all there to me: I only see matching header files for the contents of the essentia folder, but none for the other three folders under the src folder.

In any case, I added them to my project and linked the library file in the configuration, but I get a build error that says:

ld: library not found for -lessentia clang: error: linker command failed with exit code 1 (use -v to see invocation)

The method in the article also seems really labor intensive, as it involves creating a wrapper for every method/function you want to use.

I'm really stumped with this. Any help or advice would be greatly appreciated!

nckbrzg avatar Nov 16 '17 20:11 nckbrzg

Hi @willrevl and @nbranzburg I am the next guys and I am very thankful for your insights on this one, looks like you saved me a lot of time.

Still up to date and working.

Have a great day, gentlemen.

pasotee avatar Mar 22 '20 13:03 pasotee

Hi @willrevl , the steps you've mentioned -

1. Compile essentia ./waf configure --cross-compile-ios —lightweight=libav,libsamplerate --fft=ACCELERATE --build-static
2. Compile FFMPEG with libavresample
3. clone https://github.com/erikd/libsamplerate, drag files from source into a new Xcode project of type static library / framework and compile. Use the resulting .a file.

The 2nd step isn't clear to me, how should I compile FFMPEG with libavresample? And in 3rd step, should I also include essentia.a file in Xcode project for generating a static library?

rahul140490 avatar Sep 18 '21 11:09 rahul140490