I have an issue. I got a DLL written in Fortran. And I want to call this DLL in Java.
Everything is working fine for other DLLs when I try to call them from a test-Java program. The DLL is existing. Unfortunately, regardless whether I use System.load and mention the whole path or use the loadLibrary method and mention only the DLL's name the same error message is returned:
java.lang.UnsatisfiedLinkError: C:\Windows\System32\MYDLL.dll: Not enough storage is available to process this command
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1929)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1847)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at OnlyForTesting.(OnlyForTesting.java:11)
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Here is my code:
public class TryToCallDLL {
private native void method();
public static void main(String[] args){
System.out.println("Test\n");
new TryToCallDLL().method();
}
static{
System.load("C:\\Users\\xxx\\Documents\\NetBeansProjects\\JNItutorial\\src\\TryToCallDLL\\Debug\\MYDLL.dll");
}
}
I was searching for anything helpful related to similar errors but nothing was working. There was though one comment stating it could be related to a limited heap storage.
I want to emphasize that this DLL's purpose is calculating using a lot of data.
I also want to add that the DLL is a 32bit version. My PC is 64 bit, I have two Netbeans version (32bit and 64bit), but running the Java program with the 32bit version.
Any suggestions are welcomed. Thank you in advance!
EDIT:
I increased the heap in the settings: -Xmx1024m
The DLL itself has a size of 1,955 KB.
Still the DLL cannot be loaded.
Related
I'm trying to install TensorFlow for Java on Windows 10 using this Article
. I followed the steps carefully but the windows commands didn't work with me so I decided to do it manually.
The first command is to make the .jar part of the classpath and I did it manually
but the second step was to ensure that the following two files are available to the JVM: the .jar file and the extracted JNI library
but I don't know how to do that manually
The code:
package securityapplication;
import org.tensorflow.TensorFlow;
import org.tensorflow.Graph;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
public class SecurityApplication {
public static void main(String[] args) throws Exception {
try (Graph g = new Graph()) {
final String value = "Hello from " + TensorFlow.version();
// Construct the computation graph with a single operation, a constant
// named "MyConst" with a value "value".
try (Tensor t = Tensor.create(value.getBytes("UTF-8"))) {
// The Java API doesn't yet include convenience functions for adding operations.
g.opBuilder("Const", "MyConst").setAttr("dtype", t.dataType()).setAttr("value", t).build();
}
// Execute the "MyConst" operation in a Session.
try (Session s = new Session(g);
Tensor output = s.runner().fetch("MyConst").run().get(0)) {
System.out.println(new String(output.bytesValue(), "UTF-8"));
}
}
}
}
could someone help? cuz my program that uses TensorFlow still have the following error
The text in the image is :
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: windows, architecture: x86. See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/java/README.md for possible solutions (such as building the library from source). Additional information on attempts to find the native library can be obtained by adding org.tensorflow.NativeLibrary.DEBUG=1 to the system properties of the JVM.
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:66)
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:66)
at org.tensorflow.TensorFlow.init(TensorFlow.java:36)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:40)
at org.tensorflow.Graph.<clinit>(Graph.java:194)
at securityapplication.SecurityApplication.main(SecurityApplication.java:15) Java Result: 1 BUILD SUCCESSFUL (total time: 4 seconds)
The result after running the first command in cmd:
The result after running the second command in Windows PowerShell:
Any suggestions?!
Thank you
The first command failure (javac) suggests that the javac command is not in your PATH environment variables. See for example, this StackOverflow question
For the second command failure, I believe the space after -D is what is causing you trouble as Holger suggested.
IDEs like Eclipse and others also provide a means to set the java.library.path property for the JVM (see this StackOverflow answer for example).
Background: TensorFlow for Java consists of a Java library (packaged in a .jar file) and a native library (.dll on Windows, distributed in a .zip file). You need to ensure that the .jar file is in the classpath and the directory containing the .dll is in included in the java.library.path of the JVM when executing a program.
Hope that helps.
I'm using JNI to call a shared library named "libmy_jni.so" from my java code. Those are working good without any problem in other OS's but in AIX, I see the following error. I've checked that the LIBPATH and LD_LIBRARY_PATH(in case) are set correctly and matched x86 module with 32bit java(and x64 with 64bit java).
Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: my_jni (No such file or directory)
The java code loading the library is,
File sofile = new File("libmy_jni.so");
if(!sofile.exists())
{
System.out.println("can't find the moudle.");
System.exit(1);
}
System.loadLibrary("my_jni");
As I know, the most cases causing the error above are incorrect library path or unmatched 32/64bit architecture. But in my case I don't see what could be the reason.
>>file libmy_jni.so
libmy_jni.so: 64-bit XCOFF executable or object module not stripped
I have an eclipse project with two classes. The class "SomeClass1" has a native method:
SomeClass1
public class SomeClass1 {
static {
System.loadLibrary("libname"); // Load the native library.
}
public native void some_method(); // implemented in the library
// .... other non methods ....
}
The other class "SomeClass2" uses the native method of "SomeClass1". Like:
SomeClass2
public class SomeClass2{
public static void main(String[] args) {
SomeClass1 s = new SomeClass1();
s.some_method();
}
// ....other methods....
}
However when it calls that method it throws an error like this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no libname in java.library.path
....
at java.lang.System.loadLibrary(Unknown Source)
at x.x.x.SomeClass1.<clinit>(SomeClass1.java:128)
at SomeClass2.main(SomeClass2.java:10)
I think the error has something to do with java not knowing where to look for the native library.
Question1
When I use: -Djava.library.path="C:\Users.....\libfolder\" as run argument in eclipse and print the value of: System.getProperty("java.library.path"); I see alot of directories printed but not the directory that I specified in the argument. What am I doing wrong?
Question2
When I do: System.loadLibrary("name"); do I need to call the library "name.so" or "libname.so"?
Question3
If the library would be found but was a 64 bit library while the platform it is loaded on is 32 bit, would it also give a unsatisfiedLinkError or would a different error be given?
Question4
Can I specify the path to the library relative to the projects folder or relative to the file in which the library is loaded?
Hope you are able to answer (some of) my questions.
Grtz Stefan
Question 1:
You should not add this as a run argument, but as a VM argument. It's not an argument for your program, but for the JVM.
Question 2:
(Also #IanRoberts ) : The System.loadLibrary(name) call will automatically derive the name of the actual library from the given name. That means that it will append ".dll" on windows, and use "lib" + name + ".so" on linux. Otherwise, loading a native lib would not be possible in a platform-independent way!
Question 3:
In general, the UnsatsfiedLinkError is distressingly common. It's in fact true to say: The UnsatisfiedLinkError does not tell you more than "Something is wrong". You can only hope for the actual error message to be more descriptive, and this would (fortunately) be the case if you had a 32/64bit mismatch - at least on windows:
Trying to load a 32bit lib on a 64bit system will cause the message: "Can't load IA 32-bit .dll on a AMD 64-bit platform"
Trying to load a 64bit lib on a 32bit system will cause the message: "... is not a valid Win32 application"
(I'm not sure about the message for other operating systems, though, but your message indicates that the library is just not found, and not that there's a problem with the library itself)
(Question 4: I'm rather sure that this is possible, but not absolutely sure (and can't try it out) at the moment. In general, the library must be in a path that is visible via the PATH environment variable, or via the java.library.path. In doubt, it should always work then the native libs are in the same directory as where you are starting your program from)
So I have Eclipse 3.7.1, running on a 64-bit Windows 7 OS. For the first time in a while yesterday I tried writing a program and kept getting the above error. I refined my program down to a bare minimum beginners tutorial and was still getting the error. My program now is a simple readInt()s and add them together.
The code:
import acm.program.*;
public class DBEditor extends ConsoleProgram {
public void main() {
System.out.println("This adds two integers");
int a = readInt("First Num: ");
int b = readInt("Second Num: ");
int total = a+ b;
System.out.println("The sum of the numbers is: " + total);
}
}
the error when trying to run as Java Application:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
C:\Users\scarr\GCMDLN.DLL: Can't load IA 32-bit .dll on a AMD 64-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at acm.program.DOSCommandLine.getCommandLine(Program.java)
at acm.program.Program.getCommandLine(Program.java)
at acm.program.Program.main(Program.java)
How do i fix this? I am fairly rusty, so the more detailed step by step fix, the better. Thanks in advance.
Clearly the error you're getting is because something in your code tries to load a native library (DLL) and the library you have is for 32 bit Windows while you're running in 64 bit.
Take a look at the DosCommandLine.getCommandLine() method in Program.java for clues. If you absolutely need functionality provided by that library then you could download the 32 bit JRE and try to run it with it.
Switching to the 32 bit JRE when executing works for me. Below are the steps on how to do this exactly in Eclipse:
Go to Run
Go to Run configurations
Under the JRE tab you can switch to the 32 bit JRE
The issue is because you are using a .dll file for a 32bit version, while your JDK and platform are 64bit.
Go to your path "C:\Users\scarr" and you will find 2 subfolders, i386, and x64. Copy the GCMDLN.DLL from the x64 or the current .dll file, to override it.
I think the issue will be solved.
I ran in the same problem with a wrong declaration of the main or run method.
In standard java:
public static void main(String [] args) {
}
Using ConsoleProgram from the acm library I think you should be:
public void run() {
}
So run() Instead of main(). So nothing to do with the 64bit jre.
I am trying to get a hello world SWT application going:
public static void main(String args[]) throws IOException{
Display display = new Display ();
Shell shell = new Shell(display);
shell.open ();
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
But I keep getting the following exception. I have the macosx version of org.eclipse.swt.carbon being used with eclipse/maven. Has anyone seen this before?
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-carbon-3346 or swt-carbon in swt.library.path, java.library.path or the jar file
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:219)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:151)
at org.eclipse.swt.internal.C.<clinit>(C.java:21)
at org.eclipse.swt.widgets.Display.createDisplay(Display.java:943)
at org.eclipse.swt.widgets.Display.create(Display.java:937)
at org.eclipse.swt.graphics.Device.<init>(Device.java:119)
at org.eclipse.swt.widgets.Display.<init>(Display.java:749)
at org.eclipse.swt.widgets.Display.<init>(Display.java:740)
at com.wuntee.aat.command.adb.LogCat.main(LogCat.java:30)
SWT is implemented using native UI libraries - in this case, the Mac Carbon libraries - and requires some JNI code to marshal the SWT calls to the native Carbon calls. Loading JNI libraries is a little bit different than normal classloading (the dynamic libraries must first be loaded with System#loadLibrary).
First, if you're on a 64 bit machine, make sure that you're passing the -d32 argument to the JRE. (ie, java -d32 MyTestClass). The Carbon SWT libraries are 32 bit only and will not load on a 64 bit runtime.
By default, SWT tries to load the .jnilib dynamic libraries from a JAR file in your classpath - the library libswt-carbon-3346.jnilib should be in your org.eclipse.swt.carbon.macosx... JAR. SWT will try to unzip this jnilib from your JAR into a temporary location and load that.
If it can't do this for whatever reason (java.io.tmpdir isn't writable, for example) then this will fail. To work around this, you should extract libswt-carbon-3346.jnilib from the org.eclipse.swt.carbon.macosx JAR and follow the instructions that the exception provided. (For example, set swt.library.path to the location of that jnilib.)
Unrelated to your actual question: you're using SWT 3.3. A lot of changes have been made since then, including the (likely preferable) Cocoa support. Upgrading to the newest SWT libraries in the newest Eclipse may be very helpful.