Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building with libc++ on OSX #9

Closed
sarith opened this issue Aug 16, 2013 · 7 comments
Closed

Building with libc++ on OSX #9

sarith opened this issue Aug 16, 2013 · 7 comments
Milestone

Comments

@sarith
Copy link

sarith commented Aug 16, 2013

Hey there,

I've been having a great time working with this excellent library. I'm currently trying to incorporate it into a C++ project I need to build with libc++. Can someone point me in the right direction for compiling the libessentia binary against libc++ (and not libstdc++)?

I've compiled/installed all the dependencies for Essentia via Homebrew as instructed in the documentation. Would I need to recompile the dependencies with clang++/libc++ as well?

Sorry for what might be a basic question - this is my first time getting this involved with the compile/link process.

Thanks so much,
S

@wackou
Copy link
Contributor

wackou commented Aug 18, 2013

Well, this is trickier than it seems...

Normally, you should just uncomment those lines: https://github.com/MTG/essentia/blob/master/wscript#L65

However, if you do that, then this file doesn't compile anymore: https://github.com/MTG/essentia/blob/master/src/base/roguevector.h

And the problem lies in the fact that the RogueVector class relies on an implementation detail of the C++ library which uses protected inheritance in libstdc++, so we can override its behavior, but uses private inheritance in libc++... There is actually no clean way to do this with libc++, so we're stuck with libstdc++ at the moment (which is not very nice when developing with clang/libc++, I agree...).

The correct and clean solution would be to replace all uses of std::vector in Essentia using a new essentia::Vector class that would also give us the behavior of the RogueVector class (ie: can "borrow" memory from another vector, required for the streaming mode). That is however quite some bit of work...

@sarith
Copy link
Author

sarith commented Aug 19, 2013

I completely understand. I wish I had the necessary skills to contribute a solution to this issue.

In the meantime, I suppose one workable solution for my prototype would be to compile my extractor as a command line utility, execute the utility from my "host" application, write the algorithm results to a file, and then read/parse the file contents to my host libc++ application.

If anyone else has any ideas, input would be greatly appreciated.

@wackou
Copy link
Contributor

wackou commented Aug 29, 2013

Compiling the extractor as a command-line utility seems the best choice:

  • a crash in Essentia doesn't crash your host app
  • it is very easily parallelizable if you want to run an extractor on lots of files; you can also have a task queue distribute jobs depending on the number of cores available to optimize CPU usage (very adapted to running lots of tasks on a cluster)
  • you get the build system for the extractor nearly "for free", just add yours in the src/examples and edit the https://github.com/MTG/essentia/blob/master/src/examples/wscript file to add it.

@loretoparisi
Copy link

I just came across the same issue when trying to build Essentia on mobile iOS.
I ported FFTW to iOS/armv7 using this script that works (quite) good:

http://stackoverflow.com/questions/3588904/how-to-link-third-party-libraries-like-fftw3-and-sndfile-to-an-iphone-project-in

Then I put everything in XCode5 and build.

Now the error is exactly the problem depicted here:

Without having the libc++ flags active I have:

/Users/loreto/Projects/iOS/AUDIO/EssentiaTouch/EssentiaTouch/Classes/essentia/roguevector.h:127:40: No member named '_M_impl' in 'essentia::RogueVector'

My question here is

Is possibile to use instead Apple "veclib.h" from Accelerate.Framework here ?

I mean

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Headers/vecLib.h

@wackou
Copy link
Contributor

wackou commented Oct 23, 2013

the problem here is that the RogueVector class relies on an implementation detail of the std::vector class from the gnu libstdc++ that gcc links to. Clang however links against libc++ which has a different implementation and doesn't allow the RogueVector to be implemented on top of it, because all its member variables are private (they are protected in libstdc++).

If you could compile using libstdc++ instead of libc++ that should make it work.

Otherwise, the better (but more time consuming) solution would be to implement a custom vector class that would allow the RogueVector to be implemented, and change all the buffers in the streaming mode to use that vector class (instead of std::vector currently)

@loretoparisi
Copy link

I agree that the best solution would it be to implement the custom vector class. So far I'm compiling against libstdc++ and it works fine on LLVM5.0 / armv7.

That was operating in standard mode, due to too much native IO limitation with the streaming mode on armv7 devices.

Hope to see a RogueVector specific implementation and a huge refactoring then!

@wackou
Copy link
Contributor

wackou commented Dec 30, 2013

The latest version of master now builds against libc++ instead of libstdc++ on mac os. It's a big fat hack but it works, so that's what it is :-) The correct fix is still to move most of Essentia to a specific essentia::Vector (and essentia::Matrix to replace tnt::Array2D), but that will be for a later version. In the meantime, it should now compile everywhere using the native compiler and C++ standard lib (should also work on iphone, although I haven't tested it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants