Skip to content
Advertisement

Sqlite4java on Raspberry Pi

I want to use my java project on Raspberry Pi. This code depends on sqlite4java which uses native implementations for many platforms including arm processors link.

The problem is that java can’t load required sqlite wrapper for arm processor. I was doing the follows:

  1. Copied all version (tried one by one) of precompiled libraries (libsqlite4java-linux-armv5te.so, libsqlite4java-linux-armv7a.so, libsqlite4java-linux-arm.so) which I renamed to libsqlite4java-linux-arm.so.

  2. Command java -Djava.library.path=. -jar sqlite4java.jar -d gives output:

    140213:092447.509 FINE [sqlite] Internal: loading library
    140213:092447.536 FINE [sqlite] Internal: java.library.path=.
    140213:092447.538 FINE [sqlite] Internal: sqlite4java.library.path=null
    140213:092447.541 FINE [sqlite] Internal: cwd=/home/pi/sqlite4java-282/.
    140213:092447.544 FINE [sqlite] Internal: default path=/home/pi/sqlite4java-282
    140213:092447.554 FINE [sqlite] Internal: forced path=null 
    140213:092447.558 FINE [sqlite] Internal: os.name=linux; os=linux
    140213:092447.562 FINE [sqlite] Internal: os.arch=arm
    140213:092447.575 FINE [sqlite] Internal: trying to load sqlite4java-linux-arm from /home/pi/sqlite4java-282/libsqlite4java-linux-arm.so
    140213:092447.596 FINE [sqlite] Internal: cannot load sqlite4java-linux-arm from /home/pi/sqlite4java-282/libsqlite4java-linux-arm.so: java.lang.UnsatisfiedLinkError: /home/pi/sqlite4java-282/libsqlite4java-linux-arm.so: /home/pi/sqlite4java-282/libsqlite4java-linux-arm.so: cannot open shared object file: No such file or directory
    140213:092447.605 FINE [sqlite] Internal: trying to load sqlite4java-linux-arm
    140213:092447.617 FINE [sqlite] Internal: cannot load sqlite4java-linux-arm: java.lang.UnsatisfiedLinkError: /home/pi/sqlite4java-282/libsqlite4java-linux-arm.so: /home/pi/sqlite4java-282/libsqlite4java-linux-arm.so: cannot open shared object file: No such file or directory
    140213:092447.622 FINE [sqlite] Internal: trying to load sqlite4java-linux
    140213:092447.627 FINE [sqlite] Internal: cannot load sqlite4java-linux: java.lang.UnsatisfiedLinkError: no sqlite4java-linux in java.library.path
    140213:092447.638 FINE [sqlite] Internal: trying to load sqlite4java
    140213:092447.642 FINE [sqlite] Internal: cannot load sqlite4java: java.lang.UnsatisfiedLinkError: no sqlite4java in java.library.path
    140213:092447.645 FINE [sqlite] Internal: trying to load sqlite4java-linux-arm-d
    140213:092447.660 FINE [sqlite] Internal: cannot load sqlite4java-linux-arm-d: java.lang.UnsatisfiedLinkError: no sqlite4java-linux-arm-d in java.library.path
    140213:092447.676 FINE [sqlite] Internal: trying to load sqlite4java-linux-d
    140213:092447.680 FINE [sqlite] Internal: cannot load sqlite4java-linux-d: java.lang.UnsatisfiedLinkError: no sqlite4java-linux-d in java.library.path
    140213:092447.683 FINE [sqlite] Internal: trying to load sqlite4java-d
    140213:092447.699 FINE [sqlite] Internal: cannot load sqlite4java-d: java.lang.UnsatisfiedLinkError: no sqlite4java-d in java.library.path
    Error: cannot load SQLite
    java.lang.UnsatisfiedLinkError: /home/pi/sqlite4java-282/libsqlite4java-linux-arm.so: /home/pi/sqlite4java-282/libsqlite4java-linux-arm.so: cannot open shared object file: No such file or directory
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1957)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1882)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1843)
    at java.lang.Runtime.load0(Runtime.java:795)
    at java.lang.System.load(System.java:1061)
    at com.almworks.sqlite4java.Internal.tryLoadFromPath(Internal.java:337)
    at com.almworks.sqlite4java.Internal.loadLibraryX(Internal.java:117)
    at com.almworks.sqlite4java.SQLite.main(SQLite.java:368)
    
  3. Tried to set up LD_LIBRARY_PATH to /usr/lib/arm-linux-gnueabihf and /usr/lib

On given path file exists. I had installed sqlite3 and libsqlite3-dev. I’m using the latest raspbian distro on QEMU emulator:

$ uname -a
$ Linux raspberrypi 3.10.26+ #2 Fri Jan 17 22:13:59 EST 2014 armv6l GNU/Linux

Any help will be useful.

Thanks!

Advertisement

Answer

Finally I found solution. I had to build library file on Raspbian. Here are steps:

  1. Get sources from here
  2. Get sqlite_wrap.c file from here
  3. Put sqlite_wrap.c to sources directory. You need native, sqlite directories and sqlite_wrap.c file there.
  4. Create RELEASE file with content:

    #gcc
    gcc -O2 -DNDEBUG -fpic -DARM -DARCH="ARM" -DLINUX -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_LITTLE_ENDIAN -fno-omit-frame-pointer -fno-strict-aliasing -static-libgcc -I./sqlite -I/usr/lib/jvm/jdk-7-oracle-armhf/include -I/usr/lib/jvm/jdk-7-oracle-armhf/include/linux -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_STAT2 -DHAVE_READLINE=0 -DSQLITE_THREADSAFE=1 -DSQLITE_THREAD_OVERRIDE_LOCK=-1 -DTEMP_STORE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OS_UNIX=1 -c ./sqlite/sqlite3.c -o sqlite3.o
    gcc -O2 -DNDEBUG -fpic -DARM -DARCH="ARM" -DLINUX -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_LITTLE_ENDIAN -fno-omit-frame-pointer -fno-strict-aliasing -static-libgcc -I./sqlite -I/usr/lib/jvm/jdk-7-oracle-armhf/include -I/usr/lib/jvm/jdk-7-oracle-armhf/include/linux -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_STAT2 -DHAVE_READLINE=0 -DSQLITE_THREADSAFE=1 -DSQLITE_THREAD_OVERRIDE_LOCK=-1 -DTEMP_STORE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OS_UNIX=1 -c sqlite_wrap.c -o sqlite_wrap.o
    gcc -O2 -DNDEBUG -fpic -Di586 -DARCH="i586" -DLINUX -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_LITTLE_ENDIAN -fno-omit-frame-pointer -fno-strict-aliasing -static-libgcc -I./sqlite -I./native -I/usr/lib/jvm/jdk-7-oracle-armhf/include -I/usr/lib/jvm/jdk-7-oracle-armhf/include/linux -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_STAT2 -DHAVE_READLINE=0 -DSQLITE_THREADSAFE=1 -DSQLITE_THREAD_OVERRIDE_LOCK=-1 -DTEMP_STORE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OS_UNIX=1 -c ./native/sqlite3_wrap_manual.c -o sqlite3_wrap_manual.o
    gcc -O2 -DNDEBUG -fpic -Di586 -DARCH="i586" -DLINUX -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_LITTLE_ENDIAN -fno-omit-frame-pointer -fno-strict-aliasing -static-libgcc -I./sqlite -I./native -I/usr/lib/jvm/jdk-7-oracle-armhf/include -I/usr/lib/jvm/jdk-7-oracle-armhf/include/linux -DSQLITE_ENABLE_COLUMN_METADATA -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_MEMORY_MANAGEMENT -DSQLITE_ENABLE_STAT2 -DHAVE_READLINE=0 -DSQLITE_THREADSAFE=1 -DSQLITE_THREAD_OVERRIDE_LOCK=-1 -DTEMP_STORE=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OS_UNIX=1 -c ./native/intarray.c -o intarray.o
    gcc -O2 -DNDEBUG -fpic -Di586 -DARCH="i586" -DLINUX -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_LITTLE_ENDIAN -fno-omit-frame-pointer -fno-strict-aliasing -static-libgcc -shared -mno-cygwin -Wl,-soname=libsqlite4java-linux-arm.so -o libsqlite4java-linux-arm.so sqlite3.o sqlite_wrap.o sqlite3_wrap_manual.o intarray.o
    
  5. chmod +x RELEASE and run it ./RELEASE.

  6. libsqlite4java-linux-arm.so will be built, you need to copy it in proper path of your application.
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement