Java JNI problem

594 views
Skip to first unread message

feldob

unread,
Aug 24, 2010, 9:14:11 AM8/24/10
to Gurobi Optimization
Dear support team,

I am using the Eclipse IDE, trying to integrate the gurobi solver into
Java. My OS is Kubuntu lucid.

I have trouble setting up the java.library.path correctly. The native
sources refuse to work.

The gurobi.jar API is integrated, and linked to the gurobi lib folder,
in which the native libraries (libgurobi30.so and libGurobiJni30.so)
reside. No precompiler errors in the code of the example problem
("mip1"), so the interface can be accessed.

However, when attempting to run the example the following exception
pops up:

---------------------
Exception in thread "main" java.lang.UnsatisfiedLinkError:
ABSOLUTE_PATH_TO_LIB/libGurobiJni30.so: libgurobi30.so: cannot open
shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1750)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1675)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at gurobi.GurobiJni.<clinit>(GurobiJni.java:156)
at gurobi.GRBEnv.<init>(GRBEnv.java:15)
at gurobi.GRBEnv.<init>(GRBEnv.java:11)
at Mip1.main(Mip1.java:13)
-----------------------

I added the lib folders absolute path to the system variable
"LD_LIBRARY_PATH", as described in your Java reference guide.

Gurobi itself executes the example via the interactive shell once
started from the command line; no problems there.

I tried different things, like extending the java.library.path as JVM
argument, or loading the libraries via System.load("ABSOLUTEPATH")
without any success.

One thing I encountered is that libgurobi30.so is a link to
libgurobi.so.3.0.1 in the same folder; could the problem be related to
that fact?

I would appreciate any help.

Best,

Felix

Victor Pillac

unread,
Aug 24, 2010, 12:17:37 PM8/24/10
to Gurobi Optimization
Hi,

From Ubuntu/Kubuntu 9.04 the LD_LIBRARY_PATH shouldn't be set
directly, instead create a file named gurobi.conf in the directory /
etc/ld.so.conf.d/ containing the path to your Gurobi lib folder, and
then execute ldconfig.

For instance if you have gurobi installed in /opt/gurobi/linux32, run
the following commands in a terminal:
echo "/opt/gurobi/linux32/lib" | sudo tee /etc/ld.so.conf.d/
gurobi.conf
sudo ldconfig

For your information the first line prints "/opt/gurobi/linux32/lib"
in the /etc/ld.so.conf.d/gurobi.conf file, and the second update ld
library registry.

You can check that your settings are correct by running:
ldconfig -p | grep gurobi
Which should gives you a list of the gurobi libraries.

I would recommend that you revert the changes you did to permanently
set the LD_LIBRARY_PATH.

Regards

Victor

Victor Pillac

unread,
Aug 24, 2010, 12:24:34 PM8/24/10
to Gurobi Optimization
By the way, you should set the PATH and GUROBI_HOME environment
variables in file /etc/environment but be careful as you cannot use a
environment variable in the definition of another.
In other words you cannot use ${GUROBI_HOME} when defining the PATH,
but rather have something like:
PATH= "....:/opt/gurobi/linux32/bin"
GUROBI_HOME="/opt/gurobi/linux32"

Regards

Victor

Greg Glockner

unread,
Aug 24, 2010, 12:33:14 PM8/24/10
to gur...@googlegroups.com
Victor:

Thanks for the advice on how to setup the environment variables centrally. This may be useful for people who have root privileges on their Linux machines. However, someone who does not have root privileges on their Linux machine should follow the instructions in the Gurobi Quick Start manual to set the environment variables via the shell resource file (.bashrc or equivalent).

As for the original question about configuring Eclipse to use Gurobi - I was able to do that about a year ago. I'll post instructions as soon as I can find my notes.

feldob

unread,
Aug 24, 2010, 12:51:11 PM8/24/10
to Gurobi Optimization
Hi Victor,

thank you for the quick help!

What you suggested works fine now; while changing the LD_LIBRARY_PATH
directly does not even seem to work at all.

I really appreciate your help and the fine work that had been done
specifying and implementing the interfaces.

Best,

Felix

Victor Pillac

unread,
Aug 24, 2010, 2:30:06 PM8/24/10
to Gurobi Optimization
Greg,

"However, someone who does not have root privileges on their Linux
machine should follow the instructions in the Gurobi Quick Start
manual to set the environment variables via the shell resource file
(.bashrc or equivalent)."

Have you tested that with Ubuntu 9.04 or above? I used to have the
LD_LIBRARY_PATH configured this way but it stopped working with 9.04.
An explanation of this can be found here:
https://bugs.launchpad.net/ubuntu/+bug/366728
and
https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/380360

I am not sure whether or not there is a workaround for non-root users,
except manually setting the LD_LIBRARY_PATH in the terminal before
launching any Gurobi-dependent application.
To make it work with eclipse a workaround might be to create a launch
script that sets the variable, then runs eclipse, hopping that it is
kept when running the application within eclipse.

Greg Glockner

unread,
Aug 27, 2010, 6:15:21 PM8/27/10
to gur...@googlegroups.com
> I am not sure whether or not there is a workaround for non-root users,
> except manually setting the LD_LIBRARY_PATH in the terminal before
> launching any Gurobi-dependent application.
> To make it work with eclipse a workaround might be to create a launch
> script that sets the variable, then runs eclipse, hopping that it is
> kept when running the application within eclipse.

Actually, there is another way with Eclipse. I just tested it with Eclipse 3.4.2 on Ubuntu 10.04. The issue is that if you set the environment values in .bashrc, Eclipse does not utilize these settings when you launch it from Gnome or KDE. However, Eclipse lets you set environment variables from its Run Configurations window. Here are the steps for Eclipse 3.4.2; the specific menu names may be different if you're using a different version of Eclipse.

First, select Run > Run Configurations, then select your Java Application from the list on the left. In the main screen, select the tab marked Environment. Here, you can set the LD_LIBRARY_PATH environment variable to point to the lib subdirectory of Gurobi. You may have to encode the full path to the Gurobi directory since the GUROBI_HOME environment variable may not be pushed to Eclipse.

Remember that no matter how you set LD_LIBRARY_PATH, you may need to update this value when you install a new version of Gurobi.

Reply all
Reply to author
Forward
0 new messages