-
Notifications
You must be signed in to change notification settings - Fork 591
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
How to create new javacpp presets from Gradle? #65
Comments
If you're just looking to use |
Well, using gsl is just a test. Since I have got the compiled gsl.so library. In fact I want to compile my own library and use javacpp to connect to it. |
So, what happens when using it the way explained at the URL below? |
Sorry, but I'm on my Spring Festival these days. Sorry for the late reply. But I'm not looking for the gsl library. What I really need is the way to generate my own presets library for my-own c++ library. And you can assume that I've compiled my-own library into my-own.so. Now I want to call the methods in the my-own.so library. And according to the gsl library, I need two java file, both named my-own.java and one is under my-own folder (like presets/gsl.java). Now here is my question: how to write these two java files so that I can call methods in java and indirectly in c++. I've seen something like |
I understand that you are trying to wrap your own library, but what I don't understand is how it differs from something like the presets for |
Sorry for my poor expression. "call methods indirectly in c++" just means call c++ through javacpp and nothing else. What I've done is add the presets/gsl.java and gsl.java into my own project. And if I compile directly, a lot of errors like something undefined came out. Then I remove most part of gsl.java and remain only one method like this:
Then rebuild the project. Now The error is this:
It's targeting the file libs/armeabi-v7a/org/bytedeco/javacpp/gsl.java and can't find it. That's my problem. |
You'll first need to change the "include" list in the "presets" class to match your own set of include files. |
I want to use my own c++ library, but I want to use gsl as a test first. I'll need to learn how to write the gsl.java and presets/gsl.java. And I want to use the gsl function And I realize why it's looking for the /**
* @author Samuel Audet
*/
@Properties(target="org.bytedeco.javacpp.gsl", value={
@Platform(include={"gsl/gsl_types.h", "gsl/gsl_errno.h", The annotation "target" will lead the compiler to find the file under libs. So I tried to put the gsl.java and presets/gsl.java into libs. And I package the files into gsl.jar with the javac and jar command: javac org/bytedeco/javacpp/gsl.java org/bytedeco/javacpp/presets/gsl.java -cp javacpp.jar
jar -cvf gsl.jar org/bytedeco/javacpp/gsl.class org/bytedeco/javacpp/presets/gsl.class Then I got the gsl.jar file and put it into libs folder. But when install the apk into my phone, an error says In fact I found a easier way to put the java code into libs. I'm using android studio and do as this:
In this way the gradle will do the former work automatically. And of course we need to set the jdk to 1.7. After all these work, I mean putting the gsl.java and presets/gsl.java into a library, I now can call the
P.S. The libgsl.so and libgslcblas.so is putted in the android module's library folder. And I've added the gsl.jar or gsl java module as dependency of android module. Compare to the gsl-android-arm.jar, there is one file named libjnigsl.so not generated. So how can I generate the file. |
If you're trying to understand how to write new presets, it'd probably be easier to start with a smaller example such as zlib as used in this tutorial: https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets |
Ok, I read about the tutorial and checked the pom.xml files of javacpp-presets and gsl. I found I can use gradle instead of maven to do this and I made a little progress that I can generate the libjnigsl.so file. I'm using the android studio to create a new java module. Using
Which is very similar to How to use my own compiled library? #55 except the Now if I rebuild the gsl library, I'll get the libjnigsl.so file under And I copy the libjnigsl.so and also the gsl.jar to my android module. And then runs it. Now the error is:
|
Do you get the same thing if you simply use Maven instead?
|
Ok, I found it. Sorry I've been lazy to create the gsl.jar myself. But I used one downloaded from maven which version 1.16-1.1. I should have generated it by myself. Now I can generate the gsl.jar with gradle like this:
And right click on the makejar and select Which is great. Thanks for your patience. And I'm using gradle instead of maven to do all the job. If needed I can add this to the wiki too when I have the time. Thanks to javacpp and +saudet that help me working easier now. |
Yes more documentation would be welcome, thanks :) A plugin for Gradle would be nice too, if you'd like to make one. |
Is it possible to generate the |
We just need to call the Builder again on the generated Java "stubs".
That's what is being done in the tests too.
|
Thank you! That's exactly what I was missing. |
BTW, the new Mapping Recipes for C/C++ Libraries guide should be making all this clearer now. However, this doesn't resolve issues with Gradle, so a plugin for that would still be welcome. |
A build plugin for Gradle is now available here: |
Gradle JavaCPP 1.5.4 has been released! Please let me know if you try it out and have any issues with it. |
I've read about the wiki of creating new javacpp presets. But I'm faced with some problems.
I've compiled the gsl library for android-arm properly issue#55 and thanks again.
Now I want to use the gsl library. I do as the wiki but I'm not familiar with maven, so I've just add two java files to my project. Say my package path is com.my.project. So I add gsl.java and presets/gsl.java under the com.my.project directory just like the gsl presets.
And since I didn't know what the InfoMapper means, so I just copy all the content of gsl presets. And only create new gsl.java like this:
I just add the gsl_sf_bessel_J0 as a test. And here is the output:
So, why does javacpp look for the gsl.java file under org.bytedeco.javacpp.
I think I must have misunderstood something. Please help me out, thanks.
The text was updated successfully, but these errors were encountered: