Or-tools: Library not loaded: libortools.dylib

Created on 12 Sep 2016  Â·  14Comments  Â·  Source: google/or-tools

Trying to run the readme example in Unix Java for Ortools v4.3 :

➜  or-tools_MacOsX-10.11.6_v4.3.3802 javac -d objs -cp lib/com.google.ortools.jar:lib/protobuf.jar examples/com/google/ortools/samples/RabbitsPheasants.java
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):33: warning: Unsafe is internal proprietary API and may be removed in a future release
import sun.misc.Unsafe;
               ^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):46: warning: Unsafe is internal proprietary API and may be removed in a future release
  private static final sun.misc.Unsafe UNSAFE = getUnsafe();
                               ^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):111: warning: Unsafe is internal proprietary API and may be removed in a future release
  private static sun.misc.Unsafe getUnsafe() {
                         ^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):112: warning: Unsafe is internal proprietary API and may be removed in a future release
    sun.misc.Unsafe unsafe = null;
            ^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):116: warning: Unsafe is internal proprietary API and may be removed in a future release
              new PrivilegedExceptionAction<Unsafe>() {
                                            ^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):118: warning: Unsafe is internal proprietary API and may be removed in a future release
                public sun.misc.Unsafe run() throws Exception {
                               ^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):119: warning: Unsafe is internal proprietary API and may be removed in a future release
                  Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
                                ^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):119: warning: Unsafe is internal proprietary API and may be removed in a future release
                  Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
                                                     ^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
8 warnings
➜  or-tools_MacOsX-10.11.6_v4.3.3802 java -Djava.library.path=lib -cp objs:lib/com.google.ortools.jar com.google.ortools.samples.RabbitsPheasants
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/poc/Downloads/or-tools_MacOsX-10.11.6_v4.3.3802/lib/libjniortools.jnilib: dlopen(/Users/poc/Downloads/or-tools_MacOsX-10.11.6_v4.3.3802/lib/libjniortools.jnilib, 1): Library not loaded: /Users/dlahlou/Work/or-tools/lib/libortools.dylib
  Referenced from: /Users/poc/Downloads/or-tools_MacOsX-10.11.6_v4.3.3802/lib/libjniortools.jnilib
  Reason: image not found
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1861)
    at java.lang.Runtime.loadLibrary0(Runtime.java:870)
    at java.lang.System.loadLibrary(System.java:1122)
    at com.google.ortools.samples.RabbitsPheasants.<clinit>(RabbitsPheasants.java:32)

This path /Users/dlahlou/Work/or-tools/lib/libortools.dylib is not one of mine.
I have similar issue trying to update my production code which was using :

  static {
    System.loadLibrary("jniortools");
  }

Most helpful comment

Ah ah, you are a lucky man. I just solved this issue for v5.1

When using Play, .so files from your lib folder are added to -Djava.library.path.
Therefore, the java code has no problem finding libjniortools.so.
However, the C++ is not aware of the .so in your lib folder. libjniortools is not able to find libortools. To fix that, you need to set LD_LIBRARY_PATH env var to point to your lib folder.

If you want to make your play project work on OSX, I can create a sample app to demonstrate how to do that (not easy).

All 14 comments

Hi Thomas,

Can you please run "./install_libortools_mac.sh"? this should not be
required in the future releases.

I hope this helps.

Regards,

Driss

On Mon, Sep 12, 2016 at 1:31 PM, Thomas [email protected] wrote:

Trying to run the readme example in Unix Java for Ortools v4.3 :

➜ or-tools_MacOsX-10.11.6_v4.3.3802 javac -d objs -cp lib/com.google.ortools.jar:lib/protobuf.jar examples/com/google/ortools/samples/RabbitsPheasants.java
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):33: warning: Unsafe is internal proprietary API and may be removed in a future release
import sun.misc.Unsafe;
^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):46: warning: Unsafe is internal proprietary API and may be removed in a future release
private static final sun.misc.Unsafe UNSAFE = getUnsafe();
^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):111: warning: Unsafe is internal proprietary API and may be removed in a future release
private static sun.misc.Unsafe getUnsafe() {
^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):112: warning: Unsafe is internal proprietary API and may be removed in a future release
sun.misc.Unsafe unsafe = null;
^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):116: warning: Unsafe is internal proprietary API and may be removed in a future release
new PrivilegedExceptionAction() {
^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):118: warning: Unsafe is internal proprietary API and may be removed in a future release
public sun.misc.Unsafe run() throws Exception {
^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):119: warning: Unsafe is internal proprietary API and may be removed in a future release
Class k = sun.misc.Unsafe.class;
^
lib/protobuf.jar(com/google/protobuf/UnsafeUtil.java):119: warning: Unsafe is internal proprietary API and may be removed in a future release
Class k = sun.misc.Unsafe.class;
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
8 warnings
➜ or-tools_MacOsX-10.11.6_v4.3.3802 java -Djava.library.path=lib -cp objs:lib/com.google.ortools.jar com.google.ortools.samples.RabbitsPheasants
Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/poc/Downloads/or-tools_MacOsX-10.11.6_v4.3.3802/lib/libjniortools.jnilib: dlopen(/Users/poc/Downloads/or-tools_MacOsX-10.11.6_v4.3.3802/lib/libjniortools.jnilib, 1): Library not loaded: /Users/dlahlou/Work/or-tools/lib/libortools.dylib
Referenced from: /Users/poc/Downloads/or-tools_MacOsX-10.11.6_v4.3.3802/lib/libjniortools.jnilib
Reason: image not found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1861)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.google.ortools.samples.RabbitsPheasants.(RabbitsPheasants.java:32)

This path /Users/dlahlou/Work/or-tools/lib/libortools.dylib is not one of
mine.
I have similar issue trying to update my production code which was using :

static {
System.loadLibrary("jniortools");
}

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/or-tools/issues/248, or mute the thread
https://github.com/notifications/unsubscribe-auth/ASwpfGSYqrCbpV_6FksCL9sWdGHlvXO2ks5qpTf4gaJpZM4J6fMH
.

driss

The example is working.
There is a typo :

export P=`otool -L lib/libortools.dylib | grep -v ':' | grep libortools | cut -d '(' -f 1`

should be

export P=`otool -L $N/libortools.dylib | grep -v ':' | grep libortools | cut -d '(' -f 1`

I assumed that the Readme in the binaries was the same as the Readme on the root of the github depot. You should probably concatenate both readme ;)

If I want to use ortools inside a Play 2.0 project in dev mode, I have to run

`sbt clean stage`
`rsync -avh --progress scripts/ target/universal/stage/`
`cd /target/universal/stage/`
`./install_libortools_mac.sh`

I can't use sbt run or sbt test. This is blocking and will prevent use from upgrading.

Under Linux, changing *.so and *.jar, I have this issue :
[error] java.lang.UnsatisfiedLinkError: Fatal execution error, caused by /tmp/sbt_7721c4da/sbt_21a44c9d/libjniortools.so: libortools.so: cannot open shared object file: No such file or directory (CVRPPDTW.java:67)
CVRPPDTW.java:67 being System.loadLibrary("jniortools");

We are changing absolute loading paths to relative ones. This will be
available in the coming release (in few days). I'm not sure if this will
solve your problem but it should.

Regards.

On Mon, Sep 12, 2016 at 4:29 PM, Thomas [email protected] wrote:

If I want to use ortools inside a Play 2.0 project in dev mode, I have to
run

sbt clean stage
rsync -avh --progress scripts/ target/universal/stage/
cd /target/universal/stage/
./install_libortools_mac.sh

I can't use sbt run or sbt test. This is blocking and will prevent use
from upgrading.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/google/or-tools/issues/248#issuecomment-246365266,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASwpfI7guDN3_e8nMWwAXiiX0DZP4lVNks5qpWGzgaJpZM4J6fMH
.

driss

It will solve the OSX related issue but I don't get the second one, not sure it's related.

Hi @dlahlou,
Do you have any update on the octobre release ?

I'm not sure I understand your question. Do you get any errors using this
method?

On Wed, Oct 12, 2016 at 10:36 AM, Thomas [email protected] wrote:

Hi @dlahlou https://github.com/dlahlou,
I would really need to upgrade, in Java, i'm still stuck with
public boolean addDimensionWithVehicleTransitAndCapacity(SWIGTYPE_p_std__
vectorT_ResultCallback2T_long_long__RoutingModel_NodeIndex__RoutingModel_NodeIndex_t_p_t
var1, long var2, LongResultCallback1 var4, boolean var5, String var6)

Do you have any update on the octobre release ?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/or-tools/issues/248#issuecomment-253152807,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASwpfCAA1-CpFCULpeMzfQQhFXrew3JFks5qzJwYgaJpZM4J6fMH
.

driss

Hi,

I was referring to your previous message, is it still required in 4.4 ?

Can you please run "./install_libortools_mac.sh"? this should not be required in the future releases.

Ah! Actually it's not needed anymore to run "./install_libortools_mac.sh". Please let us know if you still get any errors.
Thank you.

@pocman Do you remember if/how you solved the java.lang.UnsatisfiedLinkError under Linux?
I'm having the exact same one (libjniortools.so not finding libortools.so) after building from source and running from a Play project, although in production mode.

Ah ah, you are a lucky man. I just solved this issue for v5.1

When using Play, .so files from your lib folder are added to -Djava.library.path.
Therefore, the java code has no problem finding libjniortools.so.
However, the C++ is not aware of the .so in your lib folder. libjniortools is not able to find libortools. To fix that, you need to set LD_LIBRARY_PATH env var to point to your lib folder.

If you want to make your play project work on OSX, I can create a sample app to demonstrate how to do that (not easy).

Great, solved!

What I don't understand is why this issue only happens with the libs built from source. and did not happen with 5.1 release, nor when I replaced only the libjniortools.so I built manually with the one from the 5.1 release... Are you aware of a recent change in the way libraries are loaded?

My Play project does work, but in test and production only (no run). I just saw your recent post on #163, I'm going to try this too, thanks!

on #163, the

java.lang.UnsatisfiedLinkError: com.google.ortools.constraintsolver.operations_research_constraint_solverJNI.swig_module_init()V
java.lang.UnsatisfiedLinkError: no jniortools in java.library.path
java.lang.UnsatisfiedLinkError: /tmp/sbt_689ab529/sbt_facc3145/libjniortools.so: libortools.so: cannot open shared object file: No such file or directory

was your exact error.
I do have the issue with the 5.1 release on ubuntu 14.04 (circleci)

Was this page helpful?
0 / 5 - 0 ratings