Search code examples
javaeclipseintellij-ideaidegurobi

Java unsatisfied link error in IDE but execution is seamless in terminal


I am trying to install the Gurobi software with its java interface. I have added the following lines to my .bashrc file:

export GUROBI_HOME="/opt/gurobi1001/linux64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${GUROBI_HOME}/lib"

This was requested in the installation document. Moreover, this library has a lot of test codes we can run, so I ran them by going to their directory and executing make run_java and everything executed with no problems at all. Then, I tried installing an IDE (tried Intellij and now I am using Eclipse) but I keep getting the following:

Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/faisal/gurobi1001/linux64/lib/libGurobiJni100.so: libgurobi100.so: cannot open shared object file: No such file or directory
    at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
    at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
    at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:287)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
    at java.base/java.lang.System.loadLibrary(System.java:1989)
    at gurobi.GurobiJni.<clinit>(GurobiJni.java:297)
    at gurobi.GRBEnv.<init>(GRBEnv.java:108)
    at test.Mip1.main(Mip1.java:20)

This is the same copied code as one of the test files that I ran in the terminal. Error was a bit different but I did the following: went to build path configuration and added the external jar files in the classpath (since I do not have a module-info file, I tried adding it under the module path regardless and it did not work) and added a native library location under gurobi.jar. Most solutions I have found to this error consists of doing this. I do not think there is a problem with my .bashrc file since I managed to execute the code in the terminal. The output of java --version is the following:

openjdk 17.0.5 2022-10-18
OpenJDK Runtime Environment (build 17.0.5+8-Ubuntu-2ubuntu122.04)
OpenJDK 64-Bit Server VM (build 17.0.5+8-Ubuntu-2ubuntu122.04, mixed mode, sharing)

and the IDE automatically detects JavaSE-17 so this seems fine as well.

Moreover I do not mind switching again to Intellij if anyone has a solution there. Any help would be appreciated.

enter image description here


Solution

  • This got fixed by using the following commands from : https://stackoverflow.com/a/71761881/13061992

    sudo ln -s $GUROBI_HOME/lib/libgurobi100.so /usr/lib
    sudo ln -s $GUROBI_HOME/lib/libGurobiJni100.so /usr/lib
    sudo ldconfig