-
Notifications
You must be signed in to change notification settings - Fork 583
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
Problem with std::string_view as callback parameter #606
Comments
Adapters don't always work for callback functions like this, and the problem here is that it's not possible to wrap an std::string_view in an std::string, so it's not possible to make your callback function correctly without operating on the std::string_view itself anyway. We need to provide a wrapper for that type. Obviously, we'd want that to be supported somehow by JavaCPP to general something automatically for us, but that's not currently the case. Contributions are welcome though!
Yes, things get really complicated down there with that kind of syntax. That obviously needs to be fixed. |
Thank you for the answer. I changed string_view in callback in our c++ lib to const std::string& and it works (but c++ developers don't like it). |
Maybe there is any workaround to not to change c++ code to fix string_view problem? |
Yes, if you provide a wrapper for that type, and not an adapter or something that you |
Could you give some example or link to explanation in documentation? I thought this is wrapper.
Or I should not use annotation here? |
Something like the StringArray class here: |
Hello. I've added file StringArray near my file GreeterConfig:
And I try to check how does it works in function
jni lib was created successfully but I get an error "no jniStringArray in java.library.path. Could not find jniStringArray in class, module, and library paths." |
Did you associate it with the presets for your library like this? |
Now I have added "@properties(inherit = GreeterConfig.class)" but got "no jniGreeter in java.library.path" I have 4 classes for now: GreeterConfig, which implements InfoMapper, StringArray, GreeterHelper which contains callback helper classes. And Greeter class, which generated automatically by javacpp. Should I modify my GreeterConfig somehow like class tensorflow? |
It just sounds like you skipped the build step. You'll need to build the JNI libraries before this can run. |
I have one project with mentioned java files for javacpp, it creates artefact which I use in other project with main method. Here is how I build my lib
If I call |
It doesn't look from those commands that you're building for "StringArray"... |
Sorry but I don't get it. How to build StringArray? |
From what I understand, you're not using the Maven plugin, so StringArray isn't in your pom.xml file and it's not anywhere on the command line either, and if it's not an inner class or something that JavaCPP can find through arrival.Greeter, it's not going to get built, is my guess. You'll need to give it to JavaCPP by name just like you're doing for arrival.Greeter BTW, we can probably include that class as a static class inside GreeterConfig.java. That will make things easier. |
My goal was to use StringArray in callback function. This is cpp function:
This is from my helper class
This is from mapper:
It was converted to
But I get an error
|
Yes, a
You'll need to add a |
Should I create the same wrapper if I have callback which receives enum as parameter?
Here is java callback helper:
Mapper:
Generated function:
In result I get
|
You'll need to do public native void call(@ByVal @Cast("MyError*") Pointer error); but this should also work: public native void call(MyError error); |
I would like to use
But is is not clear for me. I've modified my project to make it works like javacpp preset. So I have 2 dirs: main and gen. |
Right, that's what helper classes are for: |
We don't need to compile it at that stage since it doesn't contain any information useful for generating the files in src/gen/java. |
Finally I moved my TelemetrydHelper class from |
Just to clarify: the only problem for now is missed space symbol between callback parameter type and parameter name after generation: |
Well, we should fix this, yes. But in the end, we'll need to move to a full C++ compiler, at some point, see #51. |
I have an error during creation jni lib by javacpp in case I have function with callback with std::string_view parameter
In my case I created several c++ functions in my lib:
Also I created java helper class for javacpp:
And config:
Here is generated file:
With these settings it works ok for plainStringView function (plain function which receives string_view) and testBoolean function (function which receives callback with bool parameter), but I have an error for testStringView - function which receives callback with string_view parameter. How it can be fixed?
Also this is strange but initial file which generates javacpp contains missed space symbol between callback parameter type and parameter name: std::function<void(boolsuccess)>.
The text was updated successfully, but these errors were encountered: