Greetings,
I am trying to use this api:
http://code.google.com/p/vavi-sensor/
for using the macbook accelerometer in Java code.
I am put the .c files into my library but I am still getting a
java.lang.UnsatisfiedLinkError: no SmsWrapper in java.library.path
I assume this is because it's still in .c files while all my other libraries are .jar. How can I go about getting this into a jar or other loadable format (jnilib, etc)?
thanks
You need to read about JNI or JNA. JNA is easier, but you still need to compile the C as a library, then follow the JNA documentation.
The .c files are just source code. You need them compiled for the appropriate machine, packaged into a shared object library, and then referenced by native methods in a wrapper Java class.
The JNI tutorial has all the information you'll need, although it doesn't go into detail about the non-Java side of things as most people doing this already know about programming in C and building shared object libraries.
Related
I am facing a special situation. I am trying to run a java application within matlab. My application uses an external dll which depends on another dll (xerces-c_3_2.dll). My problem is that matlab also contains a xerces-c_3_2.dll in its root folder.
Unfortunately, these two dll files are different! It is not possible to change the library path of the jvm within matlab in a way, that the 'matlab'-version of the dll is not shadowing my dll version (it's automatically loaded on matlab startup). Due to this, my application is always throwing exceptions that a procedure could not be found because its using the wrong version.
Since matlab won't start with my version of the dll, my idea is now to rename the dll to 'xerces-c_3_2_myVersion.dll' and load it redundantly.
How can I tell the jvm for a specific jni call which native interface should be used?
In my jni interface the known
public final static native lines are defined, but I never faced the question how to specify the dll in case of redundant native functions?
Any ideas? Thank you!
Sven
I have resolved my problem:
I renamed my version of the dll file from 'xerces-c_3_2.dll' to 'xerces-c_3_s.dll'
I modified my compiled personal dll in a hex editor and changed the dependency acc. to the naming in (1)
I loaded the modified dll with the changed dependency using java within matlab. Now it's working without any problems!
So technically it was more a windows library thing rather than a java question.
Is there any way to add a C/C++ library(.lib) file into an android project to use some functions of it? I'm familiar with simple JNI implementation and calling native C functions from java. I've a C++ project with a library file, source files and header files in it. How am i supposed to create Application.mk to build .so file so that i can call those C++ functions from java?
What would be the equivalent of a library in C++ for Java? I have some classes I'd like to reuse as a library in multiple projects.
Thanks
Basically you build a jar file with the classes in, and then add a reference to that jar file on the classpath for both compilation and execution.
See the Oracle Jar File Tutorial for more information.
I have a JNI library that depends on a third party library.
I can load and use the library by first doing a System.Load on the third party library then doing System.Load on my library. This works.
I recently introduced a DllMain (does not do anything) in my library and now when the library is loaded I get java.lang.UnsatisfiedLinkError: fullpath\name.dll: Can't find dependent libraries
If I attach a native debugger to the process and set a breakpoint in the DllMain function the breakpoint is entered and the Library is loaded correctly (no UnsatisfiedLinkError )
Does anyone have any idea or pointers as to what might be going on?
I suppose that in you didn't link dlls that your dll are using to you java runtime. It must be in your working directory or use -Djava.library.path=fullpath.
Is it possible to link a C++ library to a Java program statically, in a way that will make them into a single file ,just like linking 2 C++ libraries?
(I read that java programs can also be compiled to EXE).
Theoretically this should be possible to create one EXE that already includes the required JNI functions used by the JVM.
This EXE would have to load the Java part by starting a JVM instance in the same process (by loading jvm.dll and executing it as shown in question JNI Java in c++).
The Java-EXE-wrapper I know do not support something like this as they come with a pre-compiled EXE that gets the used JAR attached as resource. Therefore I assume you would have to build you own C/C++ executable and implement all the functionality you need.
When I use JNI I include the dll with JNI support into my jar file. Then access it by classpath. You will have single jar file.
It isn't possible unless you have access to a static version of the jvm.lib library. It is distributed as a dynamic-link library referring to jvm.dll. You can't do this.