Reputation: 5181
I've got a header-only C++ library and I want to develop an Android Java app (preferably using Android Studio) that uses this library, and deploy the whole thing to a phone. Now I've assumed that having a header-only C++ library would make things easier but as it looks it's in fact the opposite and it doesn't seem to be possible to use a header-only C++ library from Java. I need to "compile" the C++ library (which is not possible with a header-only library) and then do the whole JNI stuff that one would do when there's a native C++ .a/.so library. But I'm thinking I must be overlooking something - is it not possible to use a header-only C++ library in an Android Java app?
(I'm aware of other solutions like e.g. developing an Android C++ app using Qt - but I would prefer to develop the app in Java, to save all the Qt-hassle, get reliable access to device's cameras, and have platform-native GUI.)
Upvotes: 2
Views: 353
Reputation: 7430
At the risk of pointing out the very obvious, create a file named "library.cpp" containing the following line:
#include "library.h"
Compile "library.cpp".
More likely is that this header-only library is full of template code. Templates need to be instantiated in order to generate object code. In your "library.cpp" file, explicitly instantiate the template classes you want to link to in Java.
Now, if you think you can include a template class in C++ and instantiate it as a generic in Java, you have a lot of work ahead of you, if it's even possible (which it probably won't be in general).
Upvotes: 2