Comments (10)
A call to JavaCPP_detach(attached)
is missing at the end... Could you try again with the latest version of JavaCPP to see if the same thing happens? And if so, could you also provide the FunctionPointer
declaration? Thanks!
from javacpp.
I've tried with the latest version (0.10) and I'm getting the same result.
This is the FunctionPointer declaration:
public @Name("LocalizedCaseInsensitiveCompare") int call(@Cast("const char *") String str1,@Cast("const char *") String str2, int charsToCompare)
And this is the full method (using the latest version 0.10)
int JavaCPP_com_mypackage_MyClass_00024LocalizedCaseInsensitiveCompareCallback::operator()(const char * arg0, const char * arg1, int arg2) {
jint rarg = 0;
jthrowable exc = NULL;
JNIEnv* env;
bool attached = JavaCPP_getEnv(&env);
if (env == NULL) {
goto end;
}
{
jvalue args[3];
jstring obj0 = (const char*)arg0 == NULL ? NULL : env->NewStringUTF((const char*)arg0);
args[0].l = obj0;
jstring obj1 = (const char*)arg1 == NULL ? NULL : env->NewStringUTF((const char*)arg1);
args[1].l = obj1;
args[2].i = (jint)arg2;
if (obj == NULL) {
obj = env->NewGlobalRef(JavaCPP_createPointer(env, 70));
if (obj == NULL) {
JavaCPP_log("Error creating global reference of com_mypackage_MyClass.LocalizedCaseInsensitiveCompareCallback instance for callback.");
} else {
env->SetLongField(obj, JavaCPP_addressFID, ptr_to_jlong(this));
}
ptr = &LocalizedCaseInsensitiveCompare;
}
if (mid == NULL) {
mid = JavaCPP_getMethodID(env, 70, "call", "(Ljava/lang/String;Ljava/lang/String;I)I");
}
if (env->IsSameObject(obj, NULL)) {
JavaCPP_log("Function pointer object is NULL in callback for com_mypackage_MyClass.LocalizedCaseInsensitiveCompareCallback.");
} else if (mid == NULL) {
JavaCPP_log("Error getting method ID of function caller \"public int com_mypackage_MyClass$LocalizedCaseInsensitiveCompareCallback.call(java.lang.String,java.lang.String,int)\" for callback.");
} else {
rarg = env->CallIntMethodA(obj, mid, args);
if ((exc = env->ExceptionOccurred()) != NULL) {
env->ExceptionClear();
}
}
env->DeleteLocalRef(obj0);
env->DeleteLocalRef(obj1);
}
end:
if (exc != NULL) {
jstring str = (jstring)env->CallObjectMethod(exc, JavaCPP_toStringMID);
env->DeleteLocalRef(exc);
const char *msg = env->GetStringUTFChars(str, NULL);
JavaCPP_exception e(msg);
env->ReleaseStringUTFChars(str, msg);
env->DeleteLocalRef(str);
JavaCPP_detach(attached);
throw e;
} else {
JavaCPP_detach(attached);
}
return rarg;
}
from javacpp.
On my machine, with the following files:
Foo.java
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;
public class Foo {
public static class Callback extends FunctionPointer {
public @Name("foo") int call(String a, String b, int n) throws Exception {
return n;
}
}
}
foo.cpp
#include <iostream>
#include "jniFoo.h"
int main() {
JavaCPP_init(0, NULL);
for (int i = 0; i < 1000000; i++) {
foo("foo", "bar", 42);
}
JavaCPP_uninit();
}
And the following commands:
$ javac -cp javacpp.jar Foo.java
$ java -jar javacpp.jar Foo -header
$ g++ -I/usr/lib/jvm/java/include/ -I/usr/lib/jvm/java/include/linux/ linux-x86_64/libjniFoo.so foo.cpp -o foo
$ ./foo
Nothing bad happens. Could you please tell me what results you get with that on your machine?
from javacpp.
I create Foo.java and foo.cpp and add build 10 javacpp.jar to the directory.
javac -cp javacpp.jar Foo.java works fine and creates Foo$Callback.class and Foo.class
java -jar javacpp.jar Foo -header causes this error:
Generating C:\Acronis\temp\jniFoo.cpp
Compiling C:\Acronis\temp\windows-x86\jniFoo.dll
cl "/IC:\Program Files (x86)\Java\jdk1.7.0_65\include" "/IC:\Program Files (x86)\Java\jdk1.7.0_65\include\win32" C:\Acronis\temp\jniFoo.cpp /W3 /Oi /O2 /EHsc /Gy /GL
/MD /LD /link /OUT:C:\Acronis\temp\windows-x86\jniFoo.dll "/LIBPATH:C:\Program Files (x86)\Java\jdk1.7.0_65\lib" "/LIBPATH:C:\Program Files (x86)\Java\jdk1.7.0_65\jre
\bin\server" jvm.lib
Exception in thread "main" java.io.IOException: Cannot run program "cl": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at org.bytedeco.javacpp.tools.Builder.compile(Builder.java:302)
at org.bytedeco.javacpp.tools.Builder.generateAndCompile(Builder.java:356)
at org.bytedeco.javacpp.tools.Builder.build(Builder.java:627)
at org.bytedeco.javacpp.tools.Builder.main(Builder.java:760)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(ProcessImpl.java:385)
at java.lang.ProcessImpl.start(ProcessImpl.java:136)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 4 more
from javacpp.
How are you building for the class that contains your FunctionPointer
declaration?
from javacpp.
Is there another instruction for building that class?
from javacpp.
from javacpp.
I am getting the same error as lalosoft so was following your instructions for building Foo.java and foo.cpp. You do not get an error and I do when executing your commands in order.
from javacpp.
You're on Windows, so you're going to need to install a C++ compiler separately to try this out:
https://github.com/bytedeco/javacpp#required-software
from javacpp.
Given the lack of feedback, I'm guessing this issue has been resolved, but please let me know if this is not the case! Thank you
from javacpp.
Related Issues (20)
- Parser mapping HOT 12
- 'jni.h' file not found HOT 6
- windows Cannot run program "cl" HOT 1
- std::unique_ptr fields HOT 4
- Optional pair HOT 2
- ParserException for valid c++ code HOT 1
- Function pointer returning shared_ptr HOT 10
- LNK2001: Unresolved external, issue with namespace? HOT 7
- infinite recursion when calling virtualized inherited function HOT 4
- Mapping Template Constraints, Parser Error HOT 5
- Parser cannot compile because of QT HOT 4
- Template class with template functions HOT 15
- Inadequate Error Handling HOT 1
- `@StdVector` default annotation causing `Parser` to ignore templated constructors and operator overloads with `std::vector` arguments HOT 10
- Crash when passing a unique_ptr by value HOT 12
- Potential class loading deadlock when call static methods of Loader or Pointer HOT 13
- Multiple pointer types and automatic generation of function overloads HOT 1
- Parser doesn't add @Virtual annotations HOT 2
- A question about garbage collection on native objects HOT 3
- Pointer types don't work on the native side if allocated in java HOT 16
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javacpp.