Search code examples
libusbjuce

JUCE project that builds libusb from source


I wish to create a JUCE project that makes use of libusb.

I can compile libusb and add it using ProJucer. I suppose I would also have to include libusb.h. And I would hope that we do the trick.

However it would be really nice to instead include the libusb source, so that anyone using my code doesn't require the extra step of compiling a .lib and fiddling around with JUCE's build settings.

So in Files tab I right click the root project folder -> "add existing files" and select /PathTo/MyProj/libusb/libusb/

However opening this up in Xcode, several files report:

#include <config.h> // ! not found

Even disabling non-OSX .c files in /libusb/libusb/os/ there are a couple of .c files in /libusb/libusb/ that require this config.h.

Googling, it appears that this requires a / hello it hello yeah sure Shona I'm great yeah we can go outside I guess really nice okay great and if it ever is three of them and please split over two days and it's too much of my voice Is any problem my voice is the week okay great so when when would you like me to come round okay 3 o'clock I can do integrity by.configure script to be run.

This is becoming all a bit awkward. I think from now I'm just going to compile the .lib and be done with it.

But is there any possibility of an integrated solution?

I would imagine the libusb team could make libusb more multiplatform-friendly put e.g. the contents of /os/windows*.c inside #ifdef MSVC_BLAH ... #endif just so that the whole thing compiles on every platform without prior fiddling.


Solution

  • This could be very tricky — I've learned this firsthand by trying to include GLib and Fluidsynth within a JUCE project in a very similar way you're talking about.

    You're going to run into a lot of issues if you're trying to make this cross-platform, since certain system header files that the library relies on might not be available or might need extra configuration to set up.

    There are definitely ways of doing it, most of which would involve adding lots of stuff to the Pre-Build Shell Script as well as adding the right library and header paths to the Projucer.

    A much easier method might be to just package an installer with your project they can run. It's effectively the same as having them build & install it on their own, but is very simple and easy.

    I went ahead and did this for you here.

    You could just distribute LibUSB.pkg in your project. The downside to this is that you'd need pre-built binaries for each platform, but for a simple Windows/Mac/Linux/iOS/Android app this isn't too hard to do.

    If you're hard-set on building with the source code, you'll need to add any config.h files as well — you might have to edit them to make them compile successfully.

    Also, keep in mind that LibUSB is LGPL licensed. If you edit the source code at all and use it directly in your app, you'll need to publish your app's source code under the LGPL license as well. Just linking to the library eliminates this issue.