daoud
daoud

Reputation: 25

Java CPLEX Concert UnsatisfiedLinkError

I am trying to use cplex in java using eclipse IDE on Ubuntu 16.4

and I am getting an exception "UnsatisfiedLinkError" as follows Does anybody have an idea how to overcome this exception?

Exception in thread "main" java.lang.UnsatisfiedLinkError: 'void ilog.concert.cppimpl.concert_wrapJNI.swig_module_init()'
at ilog.concert.cppimpl.concert_wrapJNI.swig_module_init(Native Method)
at ilog.concert.cppimpl.concert_wrapJNI.<clinit>(concert_wrapJNI.java:1619)
at ilog.concert.cppimpl.IloEnv.<init>(IloEnv.java:49)
at ilog.opl.IloOplFactory.<init>(IloOplFactory.java:84)
at cplex.Mulprod.main(Mulprod.java:15)

I am using the following example provided by ensta-paris Java version of mulprod.cpp of OPL distrib

import ilog.concert.*; 
import ilog.opl.*;
import ilog.opl.IloCplex;

public class Mulprod {
  static final String DATADIR = ".";

  static public void main(String[] args) throws Exception {
    int status = 127;
    try {
        IloOplFactory.setDebugMode(true);
        IloOplFactory oplF = new IloOplFactory();
        IloOplErrorHandler errHandler = oplF.createOplErrorHandler();
        IloOplModelSource modelSource = oplF.createOplModelSource(DATADIR + "/mulprod.mod");
        IloOplSettings settings = oplF.createOplSettings(errHandler);
        IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource, settings);
        IloCplex cplex = oplF.createCplex();
        cplex.setOut(null);
        IloOplModel opl = oplF.createOplModel(def, cplex);
        IloOplDataSource dataSource = oplF.createOplDataSource(DATADIR + "/mulprod.dat");
        opl.addDataSource(dataSource);
        opl.generate();
        if (cplex.solve()) {
            System.out.println("OBJECTI " + opl.getCplex().getObjValue());
            opl.postProcess();
            opl.printSolution(System.out);
        } else {
            System.out.println("No solution!");
        }
        oplF.end();
        status = 0;
    } catch (IloOplException ex) {
        System.err.println("### OPL excepti " + ex.getMessage());
        ex.printStackTrace();
        status = 2;
    } catch (IloException ex) {
        System.err.println("### CONCERT excepti " + ex.getMessage());
        ex.printStackTrace();
        status = 3;
    } catch (Exception ex) {
        System.err.println("### UNEXPECTED UNKNOWN ERROR ...");
        ex.printStackTrace();
        status = 4;
    }
    System.exit(status);
}
}

my VM arguments in run configuration are

-Djava.library.path=[cplexStudioPath]/cplex/bin/x86-64_linux:[cplexStudioPath]/opl/bin/x86-64_linux

Upvotes: 2

Views: 565

Answers (1)

Daniel Junglas
Daniel Junglas

Reputation: 5930

You also have to set the LD_LIBRARY_PATH environment variable so that it includes the OPL directory (which you also specified in java.library.path).

Also note that specifying the CPLEX directory in java.library.path is not required. I recommend removing it since you don't want libraries to get loaded from this place. You only want the libraries from the OPL directory (the required CPLEX libraries are there as well).

Upvotes: 1

Related Questions