sqlite-jdbc
sqlite-jdbc copied to clipboard
AIX: no native library
Running into below issue while running program on AIX machine.
Caused by: java.lang.Exception: No native library is found for os.name=AIX and os.arch=ppc64. path=/org/sqlite/native/AIX/ppc64 at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:335) at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:64) at org.sqlite.core.NativeDB.load(NativeDB.java:63) at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:235)
Ran checks and
- could see "AIX" support is not available in native directory.
- couldn't find entry for "AIX" in makefile as well(under source code sqlite-jdbc/Makefile).
Any pointers to resolve the issue?
Thanks.
Compile yourself and add it to LD_LIBRARY_PATH or java.library.path.
How to compile?
Run make?
Note: below changes are using IBM's c compiler(and not gcc). And I got these with the help of one of C developer. I still do not have details of few the flags that are documented below. You may need to change flags if you run into error as it may not be same on the AIX version you have.
Below steps worked for the AIX environment on I had to deploy app.
- Download org.xerial JDBC lib code. Download the correct version/TAG that is being used by SQLite JDBC jar.
- Unzip it.
- Edit
Makefile.commonas follows
- set
Default_CC := $(CROSS_PREFIX)cc--> Run "cc" at prompt to verify if it's set in "PATH" env variable. If it's not set, then set it usingexport PATH=<compiler_path>:$PATH - set
Default_STRIP := $(CROSS_PREFIX)strip -X64 - set
Default_LINKFLAGS := -qmkshrobj -lpthread -lm - set
Default_CCFLAGS := -I$(JAVA_HOME)/include -Ilib/include -Ilib/inc_linux -q64 -qcpluscmt -O2 -qmaxmem=-1 - set
Default_LIBNAME := libsqlitejdbc.a
- Run
gmake native
- this will trigger download
sqliteamagamationzip. - If your machine is behind proxy, and download fails run
gmake clean. Download the file manually and under "target" directory. Createtargetdirectory manually, as by default it will not be there. targetdirectory should be at same location asMakefile.common.
-
Once the make command succeeds, you will have native library under
target/classes/org/sqlite/native/<OS>/<arch>/libsqlitejdbc.a -
To Test add
-Dorg.sqlite.lib.path=<BASEPATH>/target/classes/org/sqlite/native/<OS>/<arch>/to java command and test it out.
Thanks.
Where can download Makefile.common? and how to add aix support?
I tried to compile using gcc, on AIX 7.3.0.0, but didn't work. Any helps?
My Steps:
- Install Packages
dnf install gcc.ppc make.ppc git.ppc
- Export Java Home
export JAVA_HOME=/usr/java8_64/
- Clone this repository
git clone https://github.com/xerial/sqlite-jdbc.git
- Compile
cd sqlite-jdbc
gmake native
As you can see below I had only warnings
Will build using target: Default (detected os: AIX, arch: ppc64) perl -p -e "s/sqlite3_api;/sqlite3_api = 0;/g"
target/sqlite-amalgamation-3450100/sqlite3ext.h > target/sqlite-3.45.1-AIX-ppc64/sqlite3ext.h perl -p -e "s/^opendb_out:/ if(!db->mallocFailed && rc==SQLITE_OK){ rc = RegisterExtensionFunctions(db); }\nopendb_out:/;"
target/sqlite-amalgamation-3450100/sqlite3.c > target/sqlite-3.45.1-AIX-ppc64/sqlite3.c.tmp perl -p -e "s/^(static const char * const sqlite3azCompileOpt.+)$/\1\n\n/* This has been automatically added by sqlite-jdbc /\n "JDBC_EXTENSIONS",/;"
target/sqlite-3.45.1-AIX-ppc64/sqlite3.c.tmp > target/sqlite-3.45.1-AIX-ppc64/sqlite3.c cat src/main/ext/.c >> target/sqlite-3.45.1-AIX-ppc64/sqlite3.c gcc -o target/sqlite-3.45.1-AIX-ppc64/sqlite3.o -c -Itarget/sqlite-3.45.1-AIX-ppc64 -Itarget/sqlite-amalgamation-3450100 -I/usr/java8_64//include -Ilib/inc_linux -Os -fPIC -fvisibility=hidden -I"/usr/java8_64/include" -I"/usr/java8_64/include/aix"
-DSQLITE_ENABLE_LOAD_EXTENSION=1
-DSQLITE_HAVE_ISNAN
-DHAVE_USLEEP=1
-DSQLITE_ENABLE_COLUMN_METADATA
-DSQLITE_CORE
-DSQLITE_ENABLE_FTS3
-DSQLITE_ENABLE_FTS3_PARENTHESIS
-DSQLITE_ENABLE_FTS5
-DSQLITE_ENABLE_RTREE
-DSQLITE_ENABLE_STAT4
-DSQLITE_ENABLE_DBSTAT_VTAB
-DSQLITE_ENABLE_MATH_FUNCTIONS
-DSQLITE_THREADSAFE=1
-DSQLITE_DEFAULT_MEMSTATUS=0
-DSQLITE_DEFAULT_FILE_PERMISSIONS=0666
-DSQLITE_MAX_VARIABLE_NUMBER=250000
-DSQLITE_MAX_MMAP_SIZE=1099511627776
-DSQLITE_MAX_LENGTH=2147483647
-DSQLITE_MAX_COLUMN=32767
-DSQLITE_MAX_SQL_LENGTH=1073741824
-DSQLITE_MAX_FUNCTION_ARG=127
-DSQLITE_MAX_ATTACHED=125
-DSQLITE_MAX_PAGE_COUNT=4294967294
-DSQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
target/sqlite-3.45.1-AIX-ppc64/sqlite3.c target/sqlite-3.45.1-AIX-ppc64/sqlite3.c: In function 'openDatabase': target/sqlite-3.45.1-AIX-ppc64/sqlite3.c:181671:48: warning: implicit declaration of function 'RegisterExtensionFunctions' [-Wimplicit-function-declaration] 181671 | if(!db->mallocFailed && rc==SQLITE_OK){ rc = RegisterExtensionFunctions(db); } | ^~~~~~~~~~~~~~~~~~~~~~~~~~ "$JAVA_HOME/bin/javac" -cp target/classpath/slf4j-api.jar -d target/common-lib -sourcepath src/main/java -h target/common-lib src/main/java/org/sqlite/core/NativeDB.java Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: src/main/java/org/sqlite/jdbc3/JDBC3Connection.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. mv target/common-lib/org_sqlite_core_NativeDB.h target/common-lib/NativeDB.h gcc -Itarget/sqlite-3.45.1-AIX-ppc64 -Itarget/sqlite-amalgamation-3450100 -I/usr/java8_64//include -Ilib/inc_linux -Os -fPIC -fvisibility=hidden -I"/usr/java8_64/include" -I"/usr/java8_64/include/aix" -I target/common-lib -c -o target/sqlite-3.45.1-AIX-ppc64/NativeDB.o src/main/java/org/sqlite/core/NativeDB.c src/main/java/org/sqlite/core/NativeDB.c: In function 'Java_org_sqlite_core_NativeDB_column_1blob': src/main/java/org/sqlite/core/NativeDB.c:991:71: warning: passing argument 5 of '(*env)->SetByteArrayRegion' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 991 | (env)->SetByteArrayRegion(env, jBlob, (jsize) 0, (jsize) length, (const jbyte) blob); | ^~~~~~~~~~~~~~~~~~~ src/main/java/org/sqlite/core/NativeDB.c:991:71: note: expected 'jbyte *' {aka 'signed char *'} but argument is of type 'const jbyte *' {aka 'const signed char *'} src/main/java/org/sqlite/core/NativeDB.c: In function 'Java_org_sqlite_core_NativeDB_value_1blob': src/main/java/org/sqlite/core/NativeDB.c:1237:71: warning: passing argument 5 of '(*env)->SetByteArrayRegion' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] 1237 | (env)->SetByteArrayRegion(env, jBlob, (jsize) 0, (jsize) length, (const jbyte) blob); | ^~~~~~~~~~~~~~~~~~~ src/main/java/org/sqlite/core/NativeDB.c:1237:71: note: expected 'jbyte *' {aka 'signed char *'} but argument is of type 'const jbyte *' {aka 'const signed char *'} gcc -Itarget/sqlite-3.45.1-AIX-ppc64 -Itarget/sqlite-amalgamation-3450100 -I/usr/java8_64//include -Ilib/inc_linux -Os -fPIC -fvisibility=hidden -I"/usr/java8_64/include" -I"/usr/java8_64/include/aix" -o target/sqlite-3.45.1-AIX-ppc64/libsqlitejdbc.so target/sqlite-3.45.1-AIX-ppc64/NativeDB.o target/sqlite-3.45.1-AIX-ppc64/sqlite3.o -shared -static-libgcc -pthread -lm cp target/sqlite-3.45.1-AIX-ppc64/libsqlitejdbc.so /tmp/libsqlitejdbc.so strip /tmp/libsqlitejdbc.so cp /tmp/libsqlitejdbc.so target/sqlite-3.45.1-AIX-ppc64/libsqlitejdbc.so cp target/sqlite-3.45.1-AIX-ppc64/libsqlitejdbc.so src/main/resources/org/sqlite/native/AIX/ppc64/libsqlitejdbc.so cp target/sqlite-3.45.1-AIX-ppc64/libsqlitejdbc.so target/classes/org/sqlite/native/AIX/ppc64/libsqlitejdbc.so
- Copy library libsqlitejdbc
cp target/sqlite-3.45.1-AIX-ppc64/libsqlitejdbc.so libsqlitejdbc.a
- Check the libsqlitejdbc.a
file libsqlitejdbc.a
libsqlitejdbc.a: executable (RISC System/6000) or object module
- Compile Sample.java
java Sample.java
- Run the Sample.java
java -cp .:slf4j-api-2.0.12.jar:sqlite-jdbc-3.45.1.0.jar -Dorg.sqlite.lib.path=./libsqlitejdbc.a Sample
But native library could not be founded.
SLF4J(W): No SLF4J providers were found. SLF4J(W): Defaulting to no-operation (NOP) logger implementation SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details. Error opening connection java.sql.SQLException: Error opening connection at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:283) at org.sqlite.SQLiteConnection.
(SQLiteConnection.java:67) at org.sqlite.jdbc3.JDBC3Connection. (JDBC3Connection.java:28) at org.sqlite.jdbc4.JDBC4Connection. (JDBC4Connection.java:19) at org.sqlite.JDBC.createConnection(JDBC.java:106) at org.sqlite.JDBC.connect(JDBC.java:79) at java.sql.DriverManager.getConnection(DriverManager.java:675) at java.sql.DriverManager.getConnection(DriverManager.java:281) at Sample.main(Sample.java:16) Caused by: org.sqlite.NativeLibraryNotFoundException: No native library found for os.name=AIX, os.arch=ppc64, paths=[./libsqlitejdbc.a:/usr/java8_64/jre/lib/ppc64/compressedrefs:/usr/java8_64/jre/lib/ppc64:/usr/java8_64/jre/lib/ppc64/j9vm:/usr/java8_64/jre/lib/ppc64:/usr/java8_64/jre/../lib/ppc64:/usr/java8_64/jre//lib/icc:/usr/lib64:/usr/lib] at org.sqlite.SQLiteJDBCLoader.loadSQLiteNativeLibrary(SQLiteJDBCLoader.java:361) at org.sqlite.SQLiteJDBCLoader.initialize(SQLiteJDBCLoader.java:75) at org.sqlite.core.NativeDB.load(NativeDB.java:69) at org.sqlite.SQLiteConnection.open(SQLiteConnection.java:280) ... 8 more