Question

When I try to use LPSolve for Java (mavenized version, http://code.google.com/p/lpsolve-java/source/checkout ), I get following error:

java.lang.UnsatisfiedLinkError: C:\Windows\System32\lpsolve55j.dll: Can't find dependent libraries
     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.loadLibrary0(Unknown Source)
     at java.lang.System.loadLibrary(Unknown Source)
     at lpsolve.LpSolve.<clinit>(LpSolve.java:274)

I

  • put lpsolve55j.dll in Windows\System32 and
  • added the directory C:\Program Files\LPSolve IDE to the PATH environment variable.

The error occurs both in eclipse (test case) as well as during execution of "mvn test".

None of this helps.

How can I fix this error?

Was it helpful?

Solution

I did the following thing and it seems to work:

  1. Downloaded the dev package that fits my processor (64 bit)
  2. Extracted the archive into a folder
  3. Copied lpsolve55j.jar and lpsolve55j.dll into the directory from step 2
  4. Added the directory from step 2 to the PATH
  5. Included lpsolve55j.jar from the directory in step 2 into my java project (as an external directory).

Now it works.

OTHER TIPS

I did the following thing and it works 100%:

Downloaded these two files "lpsolve55.dll" & "lpsolve55j.dll"
Copy these files and paste inside these folders "C:\Program Files\Java\jdk1.6.0_25\bin" and "C:\Program Files\Java\jre6\bin"
Put these two files "lpsolve55.dll" & "lpsolve55j.dll" in your project Folder also.

Now it works.

For my Windows 64bit maven, I just downloaded lp_solve_5.5.2.5_dev_win64.zip and lp_solve_5.5.2.5_java.zip, Unzip them do the following two things:

1) add lpsolve55j.jar to maven dependency, in my case it is as follows:
          <dependency>
            <groupId>lpsolver55j</groupId>
            <artifactId>lpsolve55j</artifactId>
            <scope>system</scope>
            <systemPath>${basedir}/lib/lpsolve55j.jar</systemPath>
            <version>55</version>
        </dependency>   
2) put lpsolve55.dll, lpsolve55j.dll into C:\Windows\System32. Be sure these two dlls are both 64 bit.

Then it works. Those step are also mentioned in unzipped lp_solve_5.5.2.5_java directory's readme file, Installation Section

lp_solve_5.5_java/README.html

Setup for LPSolve

1.Go to https://sourceforge.net/projects/lpsolve/files/ -> click on LpSolve You will see different versions of LPSolve. Download lp_solve_5.5.2.5_dev_win64.zip (according to processor type ) lp_solve_5.5.2.5_java.zip (for java)

2.Extract both the files( lp_solve_5.5.2.5_dev_win64 and lp_solve_5.5.2.5_java folder )

3.Create a maven project using eclipse.( Demo project)

4.Goto lp_solve_5.5.2.5_java folder and copy lib folder and paste it into the root of your project directory. (lib folder contains supporting files of processor type (win64,win32 etc )and jar file of LPSolve i.e “lpsolve55j.jar”).

5.Right click on Demo Project->Build Path->Configure Build Path->Libraries->Add External jars->navigate to your project directory->lib -> select “lpsolve55j.jar”->open->apply->’apply and close.

6.Goto lp_solve_5.5.2.5_dev_win64 folder copy ”lpsolve55.dll” and paste it into C:\Windows folder.

7.Goto lib->win64->copy “lpsolve55j.dll” and paste it into C:\Windows folder.

8.Create a new class Demo

9.http://lpsolve.sourceforge.net/5.5/ use this as a reference guide.

10.copy and paste simple example and run the application.

import lpsolve.*;
public class Demo {

  public static void main(String[] args) {
    try {
      // Create a problem with 4 variables and 0 constraints
      LpSolve solver = LpSolve.makeLp(0, 4);

      // add constraints
      solver.strAddConstraint("3 2 2 1", LpSolve.LE, 4);
      solver.strAddConstraint("0 4 3 1", LpSolve.GE, 3);

      // set objective function
      solver.strSetObjFn("2 3 -2 3");

      // solve the problem
      solver.solve();

      // print solution
      System.out.println("Value of objective function: " + solver.getObjective());
      double[] var = solver.getPtrVariables();
      for (int i = 0; i < var.length; i++) {
        System.out.println("Value of var[" + i + "] = " + var[i]);
      }

      // delete the problem and free memory
      solver.deleteLp();
    }
    catch (LpSolveException e) {
       e.printStackTrace();
    }
  }
}

if you get this error:java.lang.unsatisfiedlinkerror no lpsolve55j in java.library.path

Setting the java.library path. using Eclipse

1.Select your project in the Package Explorer area and press a right click on it.

2.Select Build Path → Configure Build Path... option.

3.In the appearing window, select the Libraries tab.

4.Then, expand the JRE System library option and select the Native library location.

5.Click on the Edit... button at the right panel.

6.Locate the required library and then click OK.

7.Close the window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top