Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Java linking error

    Posted 05/18/14 04:06 PM

    I've run into a linking error that has me stumped. I'm coding in Java, on Linux, using the NetBeans IDE. I have two projects (A and B), with A creating a library jar file and B creating a user program. Both include the CPLEX 12.6 jar file among their respective compilation libraries, and B includes A's jar file. Both find the path to the CPLEX binary file on the LD_LIBRARY_PATH environment variable. A contains a MIP model, and B contains its own MIP model as well as calling methods in A.

    Everything worked fine until I added an aborter to the MIP in A. In one of A's classes, I include the lines

    private final Aborter aborter;

    at the top of the class and

    aborter = new Aborter();  // * problem occurs here

    in the class constructor. (Attaching the aborter to an instance of IloCplex() comes later, and as it turns out never happens because the code dies before then.)

    Project A contains its own demo program. After cleaning and building A, I can run A's demo (which among other things attaches the aborter to an instance of IloCplex) and everything runs fine. When I run B, however, I get a run time exception at the point where A's constructor (called from B) hits the indicated line. The exception message is "java.lang.UnsatisfiedLinkError: ilog.cplex.Cplex.newNativeInt()J".

    I found a somewhat ugly work-around by moving the code that declares and attaches the aborter from A to B, but I'd like to be able to move it back someday. (Other programs besides B may want the option to abort a long solve in A.) Frankly, I'm baffled as to how I can be getting an unsatisfied link error when B calls A when the same link apparently is made when I run the main method in A. Anyone have any clues to share?

    Thanks,

    Paul

     


    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Java linking error

    Posted 05/19/14 01:47 AM

    You can reproduce this issue with a very small program:

    import ilog.cplex.IloCplex.Aborter;
    
    public class Main {
        public static void main(String[] args) {
                    Aborter aborter = new Aborter();
                    aborter.abort();
                    aborter.clear();
                    aborter.end();
            }
    }
    

    The problem is that creating a new aborter does not imply loading the CPLEX shared library, hence you get this unsatisfied link error. In order to fix the problem you can add this code to the class that creates the aborter in its constructor:

    static {
            try { new IloCplex().end(); }
            catch (IloException ignored) {}
    }
    

    This forces the CPLEX shared library to be pulled in when the class is loaded.


    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Java linking error

    Posted 05/21/14 04:43 PM

     

    Thanks, Daniel! Your fix works fine for me. Should I file an enhancement request to get Aborter to work the way IloCplex does, or is this something that likely has to stay the way it is?


    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Java linking error

    Posted 05/22/14 12:24 AM

    I have already recorded this as a bug. So there is no need to file an enhancement request.


    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Java linking error

    Posted 05/22/14 04:43 PM