JavaCPP - how to actually generate the C++ JNI wrappers?
I'm trying to use JavaCPP to create java bindings for some C++ library. The process has 2 aspects
- A linux shared library (.so) needs to be built, containing the native entry points (JNIEXPORT). It so happens my library is header-only so I just pass the includes to JavaCPP
- A java class needs to be generated with methods using the "native" keyword, whose signatures correspond to those on the native side
The Java "properties" file (the part which describes how to build the .so and how to generate the Java file) looks like this:
@Properties(
//target = "Client", // NOTE: with this commented, .so gets built; with it enabled, Java class gets written
value = @Platform(
includepath = {"jnigen/src/main/cpp/mpf"},
include = "ClientWrapper.hpp"
)
)
public class Mpf implements InfoMapper {
public void map(InfoMap infoMap) {
infoMap.put(new Info("mpf::ClientWrapper").pointerTypes("Client"));
}
}
The problem is, I can't for the life of me generate the C++ bindings. I know because the .so doesn't contain the entry points, looking at it with nm -D X.so
. If I specify a "target" property the Java class gets outputted, which does look good, but no .so
. If I leave out target
property, the .so is successfully built, but it has no bindings. I also see it hasn't got them, by passing -nodelete to the java -jar javacpp.jar
so it keeps the generated cpp files - they only have marshalling code inside and not my stuff (one class).
The JavaCPP documentation is a nightmare, and the steps are so entagled I can't work it out. Suggestions for alternative libraries are also welcome. Thanks.
java c++ jni native javacpp
add a comment |
I'm trying to use JavaCPP to create java bindings for some C++ library. The process has 2 aspects
- A linux shared library (.so) needs to be built, containing the native entry points (JNIEXPORT). It so happens my library is header-only so I just pass the includes to JavaCPP
- A java class needs to be generated with methods using the "native" keyword, whose signatures correspond to those on the native side
The Java "properties" file (the part which describes how to build the .so and how to generate the Java file) looks like this:
@Properties(
//target = "Client", // NOTE: with this commented, .so gets built; with it enabled, Java class gets written
value = @Platform(
includepath = {"jnigen/src/main/cpp/mpf"},
include = "ClientWrapper.hpp"
)
)
public class Mpf implements InfoMapper {
public void map(InfoMap infoMap) {
infoMap.put(new Info("mpf::ClientWrapper").pointerTypes("Client"));
}
}
The problem is, I can't for the life of me generate the C++ bindings. I know because the .so doesn't contain the entry points, looking at it with nm -D X.so
. If I specify a "target" property the Java class gets outputted, which does look good, but no .so
. If I leave out target
property, the .so is successfully built, but it has no bindings. I also see it hasn't got them, by passing -nodelete to the java -jar javacpp.jar
so it keeps the generated cpp files - they only have marshalling code inside and not my stuff (one class).
The JavaCPP documentation is a nightmare, and the steps are so entagled I can't work it out. Suggestions for alternative libraries are also welcome. Thanks.
java c++ jni native javacpp
The command for generating the JNI headers isjavah
did you run that? I think your java version might be relevant to the answer. here's the tutorial I used in early 2017. Thank google for saving all my history. I'm using java 8
– Chris Mc
Nov 22 '18 at 2:17
I know aboutjavah
(orjavac -h
) but I was under the impression JavaCPP would do this for you, since it parses the C++ project and generates the Java side of things. Running javah would be the easier things it does.
– haelix
Nov 22 '18 at 10:36
Oh and you tutorial doesn't have to do with the JavaCPP library, it's barebone JNI (which I'm switching to).
– haelix
Nov 22 '18 at 10:37
add a comment |
I'm trying to use JavaCPP to create java bindings for some C++ library. The process has 2 aspects
- A linux shared library (.so) needs to be built, containing the native entry points (JNIEXPORT). It so happens my library is header-only so I just pass the includes to JavaCPP
- A java class needs to be generated with methods using the "native" keyword, whose signatures correspond to those on the native side
The Java "properties" file (the part which describes how to build the .so and how to generate the Java file) looks like this:
@Properties(
//target = "Client", // NOTE: with this commented, .so gets built; with it enabled, Java class gets written
value = @Platform(
includepath = {"jnigen/src/main/cpp/mpf"},
include = "ClientWrapper.hpp"
)
)
public class Mpf implements InfoMapper {
public void map(InfoMap infoMap) {
infoMap.put(new Info("mpf::ClientWrapper").pointerTypes("Client"));
}
}
The problem is, I can't for the life of me generate the C++ bindings. I know because the .so doesn't contain the entry points, looking at it with nm -D X.so
. If I specify a "target" property the Java class gets outputted, which does look good, but no .so
. If I leave out target
property, the .so is successfully built, but it has no bindings. I also see it hasn't got them, by passing -nodelete to the java -jar javacpp.jar
so it keeps the generated cpp files - they only have marshalling code inside and not my stuff (one class).
The JavaCPP documentation is a nightmare, and the steps are so entagled I can't work it out. Suggestions for alternative libraries are also welcome. Thanks.
java c++ jni native javacpp
I'm trying to use JavaCPP to create java bindings for some C++ library. The process has 2 aspects
- A linux shared library (.so) needs to be built, containing the native entry points (JNIEXPORT). It so happens my library is header-only so I just pass the includes to JavaCPP
- A java class needs to be generated with methods using the "native" keyword, whose signatures correspond to those on the native side
The Java "properties" file (the part which describes how to build the .so and how to generate the Java file) looks like this:
@Properties(
//target = "Client", // NOTE: with this commented, .so gets built; with it enabled, Java class gets written
value = @Platform(
includepath = {"jnigen/src/main/cpp/mpf"},
include = "ClientWrapper.hpp"
)
)
public class Mpf implements InfoMapper {
public void map(InfoMap infoMap) {
infoMap.put(new Info("mpf::ClientWrapper").pointerTypes("Client"));
}
}
The problem is, I can't for the life of me generate the C++ bindings. I know because the .so doesn't contain the entry points, looking at it with nm -D X.so
. If I specify a "target" property the Java class gets outputted, which does look good, but no .so
. If I leave out target
property, the .so is successfully built, but it has no bindings. I also see it hasn't got them, by passing -nodelete to the java -jar javacpp.jar
so it keeps the generated cpp files - they only have marshalling code inside and not my stuff (one class).
The JavaCPP documentation is a nightmare, and the steps are so entagled I can't work it out. Suggestions for alternative libraries are also welcome. Thanks.
java c++ jni native javacpp
java c++ jni native javacpp
asked Nov 21 '18 at 23:15
haelixhaelix
1,57932033
1,57932033
The command for generating the JNI headers isjavah
did you run that? I think your java version might be relevant to the answer. here's the tutorial I used in early 2017. Thank google for saving all my history. I'm using java 8
– Chris Mc
Nov 22 '18 at 2:17
I know aboutjavah
(orjavac -h
) but I was under the impression JavaCPP would do this for you, since it parses the C++ project and generates the Java side of things. Running javah would be the easier things it does.
– haelix
Nov 22 '18 at 10:36
Oh and you tutorial doesn't have to do with the JavaCPP library, it's barebone JNI (which I'm switching to).
– haelix
Nov 22 '18 at 10:37
add a comment |
The command for generating the JNI headers isjavah
did you run that? I think your java version might be relevant to the answer. here's the tutorial I used in early 2017. Thank google for saving all my history. I'm using java 8
– Chris Mc
Nov 22 '18 at 2:17
I know aboutjavah
(orjavac -h
) but I was under the impression JavaCPP would do this for you, since it parses the C++ project and generates the Java side of things. Running javah would be the easier things it does.
– haelix
Nov 22 '18 at 10:36
Oh and you tutorial doesn't have to do with the JavaCPP library, it's barebone JNI (which I'm switching to).
– haelix
Nov 22 '18 at 10:37
The command for generating the JNI headers is
javah
did you run that? I think your java version might be relevant to the answer. here's the tutorial I used in early 2017. Thank google for saving all my history. I'm using java 8– Chris Mc
Nov 22 '18 at 2:17
The command for generating the JNI headers is
javah
did you run that? I think your java version might be relevant to the answer. here's the tutorial I used in early 2017. Thank google for saving all my history. I'm using java 8– Chris Mc
Nov 22 '18 at 2:17
I know about
javah
(or javac -h
) but I was under the impression JavaCPP would do this for you, since it parses the C++ project and generates the Java side of things. Running javah would be the easier things it does.– haelix
Nov 22 '18 at 10:36
I know about
javah
(or javac -h
) but I was under the impression JavaCPP would do this for you, since it parses the C++ project and generates the Java side of things. Running javah would be the easier things it does.– haelix
Nov 22 '18 at 10:36
Oh and you tutorial doesn't have to do with the JavaCPP library, it's barebone JNI (which I'm switching to).
– haelix
Nov 22 '18 at 10:37
Oh and you tutorial doesn't have to do with the JavaCPP library, it's barebone JNI (which I'm switching to).
– haelix
Nov 22 '18 at 10:37
add a comment |
1 Answer
1
active
oldest
votes
The new Mapping Recipes for C/C++ Libraries wiki page should clarify all this, but let me know if there is still anything unclear, and I will provide additional precisions here.
In this case, we could call JavaCPP on Mpf
with the @Properties(target="Client", ...)
value set, creating a class called Client
, so the series of commands would look like this:
$ javac -cp javacpp.jar Mpf.java
$ java -jar javacpp.jar Mpf
$ javac -cp javacpp.jar Client.java
$ java -jar javacpp.jar Client
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421770%2fjavacpp-how-to-actually-generate-the-c-jni-wrappers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The new Mapping Recipes for C/C++ Libraries wiki page should clarify all this, but let me know if there is still anything unclear, and I will provide additional precisions here.
In this case, we could call JavaCPP on Mpf
with the @Properties(target="Client", ...)
value set, creating a class called Client
, so the series of commands would look like this:
$ javac -cp javacpp.jar Mpf.java
$ java -jar javacpp.jar Mpf
$ javac -cp javacpp.jar Client.java
$ java -jar javacpp.jar Client
add a comment |
The new Mapping Recipes for C/C++ Libraries wiki page should clarify all this, but let me know if there is still anything unclear, and I will provide additional precisions here.
In this case, we could call JavaCPP on Mpf
with the @Properties(target="Client", ...)
value set, creating a class called Client
, so the series of commands would look like this:
$ javac -cp javacpp.jar Mpf.java
$ java -jar javacpp.jar Mpf
$ javac -cp javacpp.jar Client.java
$ java -jar javacpp.jar Client
add a comment |
The new Mapping Recipes for C/C++ Libraries wiki page should clarify all this, but let me know if there is still anything unclear, and I will provide additional precisions here.
In this case, we could call JavaCPP on Mpf
with the @Properties(target="Client", ...)
value set, creating a class called Client
, so the series of commands would look like this:
$ javac -cp javacpp.jar Mpf.java
$ java -jar javacpp.jar Mpf
$ javac -cp javacpp.jar Client.java
$ java -jar javacpp.jar Client
The new Mapping Recipes for C/C++ Libraries wiki page should clarify all this, but let me know if there is still anything unclear, and I will provide additional precisions here.
In this case, we could call JavaCPP on Mpf
with the @Properties(target="Client", ...)
value set, creating a class called Client
, so the series of commands would look like this:
$ javac -cp javacpp.jar Mpf.java
$ java -jar javacpp.jar Mpf
$ javac -cp javacpp.jar Client.java
$ java -jar javacpp.jar Client
edited Dec 25 '18 at 0:49
answered Dec 24 '18 at 6:43
Samuel AudetSamuel Audet
3,9081725
3,9081725
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421770%2fjavacpp-how-to-actually-generate-the-c-jni-wrappers%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The command for generating the JNI headers is
javah
did you run that? I think your java version might be relevant to the answer. here's the tutorial I used in early 2017. Thank google for saving all my history. I'm using java 8– Chris Mc
Nov 22 '18 at 2:17
I know about
javah
(orjavac -h
) but I was under the impression JavaCPP would do this for you, since it parses the C++ project and generates the Java side of things. Running javah would be the easier things it does.– haelix
Nov 22 '18 at 10:36
Oh and you tutorial doesn't have to do with the JavaCPP library, it's barebone JNI (which I'm switching to).
– haelix
Nov 22 '18 at 10:37