deephacks / lmdbjni

LMDB for Java
Apache License 2.0
204 stars 28 forks source link

LD_LIBRARY_PATH setup #77

Closed purplefox closed 7 years ago

purplefox commented 7 years ago

Hi,

I've followed the instructions on the README to create a helloworld example. I'm using the same maven deps from the README and getting:

Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load library. Reasons: [no lmdbjni32-0.4.6 in java.library.path, no lmdbjni-0.4.6 in java.library.path, no lmdbjni in java.library.path]

When trying to run a simple example in IntelliJ IDEA. It's not mentioned in the README but I assume I have to setup LD_LIBRARY_PATH to get this to work. Do you have any pointers?

purplefox commented 7 years ago

I ended up using the maven dependency plugin to unpack the jars to a directory where I can see the native libs then added those to java.library.path. Not sure if this is the "recommended" way.

I'm using Linux 64 bit, but when running I get:

java.lang.UnsatisfiedLinkError: Could not load library. Reasons: [no lmdbjni32-0.4.6 in java.library.path, no lmdbjni-0.4.6 in java.library.path, /home/tim/projects/mewbase/target/nativelib/META-INF/native/linux64/liblmdbjni.so: /home/tim/projects/mewbase/target/nativelib/META-INF/native/linux64/liblmdbjni.so: wrong ELF class: ELFCLASS64 (Possible cause: architecture word width mismatch)]

Not sure why it's looking for a 32 bit version.... I'd expect wrong ELF class if its trying to load a 32 bit so on 64 bit arch, but I only added the 64 bit dependency to the pom.xml.

At this point I'm struggling, do you by any chance have a simple Maven helloworld project showing usage of this project? It would be really helpful :)

krisskross commented 7 years ago

It should work if you have the correct dependencies. No need to set LD_LIBRARY_PATH or any other configuration. This is all that's needed on 64-bit linux.

<dependency>
  <groupId>org.deephacks.lmdbjni</groupId>
  <artifactId>lmdbjni-linux64</artifactId>
  <version>0.4.6</version>
</dependency>

What distro are you running?

purplefox commented 7 years ago

Adding the dependency as above is the first thing I tried. I get: testFoo(com.tesco.mewbase.doc.impl.lmdb.LmdbDocManagerTest): Could not load library. Reasons: [no lmdbjni32-0.4.6 in java.library.path, no lmdbjni-0.4.6 in java.library.path, no lmdbjni in java.library.path]

if just doing that.

I am running Ubuntu 14.04.5 LTS

purplefox commented 7 years ago

This is the pom I am using:

https://github.com/Tesco/mewbase/blob/lmdb/pom.xml

purplefox commented 7 years ago

Seems strange it is looking for the 32 bit shared lib

krisskross commented 7 years ago

Sounds like you may have an environment variable set that confuse the library lookup. There are a few variables that are used in order to load the native library.

krisskross commented 7 years ago

https://github.com/fusesource/hawtjni/blob/master/hawtjni-runtime/src/main/java/org/fusesource/hawtjni/runtime/Library.java

krisskross commented 7 years ago

The lookup is supposed to unzip the .so files and load them automatically. You could debug your way through that source file and you'll probably find the reason it doesn't find the library.

purplefox commented 7 years ago

I don't seem to have any special env vars set, and also I don't set CLASSPATH

krisskross commented 7 years ago

I suspect that the exception is thrown from here? Could you step debug this method and tell me where the errors are picked up?

purplefox commented 7 years ago

It seems that os.arch is returning i386 although I am running on x86_64. Investigating.. perhaps a 32 bit JVM is installed for some reason...

purplefox commented 7 years ago

Problem solved, indeed it was a 32 bit JVM installed on this machine. Installed a 64 bit one and now it works. Thanks for your help.

krisskross commented 7 years ago

Great! No problem.