Sqlite load extension disabled?

I am trying to use this sqlite extension to calculate stdev in Sqlite dbs, on Linux I use this command to compile lib

gcc -fPIC -lm -shared extension-functions.c -o libsqlitefunctions.so

but it seems that the .load command is not in the sqlite.help command list, and I got an error:

unknown command or invalid arguments: "load". Enter ".help" for reference

The same thing happens when I use the command:

sqlite> SELECT load_extension('./libsqlitefunctions.so'); 

SQL error: no such function: load_extension

I tried using this instruction to compile sqlite:

 0. untar latest sqlite3 source code in a new directory 1. cd to the newly untarred sqlite directory 2. Comment out the line in Makefile.in to enable loadable extensions: # TCC += -DSQLITE_OMIT_LOAD_EXTENSION=1 3. ./configure LIBS=-ldl && make sqlite3 4. export LD_LIBRARY_PATH="`pwd`:$LD_LIBRARY_PATH" 5. gcc -I`pwd` -shared src/test_loadext.c -o half.so 6. ./sqlite3 

But the line "TCC + = -DSQLITE_OMIT_LOAD_EXTENSION = 1" could not be found in the latest Sqlite source code.

+4
source share
2 answers

It looks like configure been updated, but not the documentation. Try

 ./configure --enable-dynamic-extensions 

Link is the configure source code. Digging further, it seems that dynamic extensions are enabled by default. From README :

 The generic installation instructions for autoconf/automake are found in the INSTALL file. The following SQLite specific boolean options are supported: --enable-readline use readline in shell tool [default=yes] --enable-threadsafe build a thread-safe library [default=yes] --enable-dynamic-extensions support loadable extensions [default=yes] 

So, I think load present. This is the second part of the invalid argument error that the problem is.

It looks like you are using Linux instructions. This will not work. Typically, a Mac does not have .so files that your compilation team generates.

The method for compiling and loading the dynamic Mac library loaded as an extension is at this location . The compilation command will look something like this:

 gcc -bundle -fPIC -I/path-to-sqlite/sqlite3 -o filename.sqlext filename.c 

Note the -bundle and -fPIC , which are important for dynamic loading, but which you were missing. The resulting file name will be filename.sqlext , so use it in your path.

+1
source

It may be worth noting that when loading the library you may get a "missing character" error - this is because the -lm flag should be at the end of the compilation command, like this:

gcc -fPIC -supported extensions-functions.c -o libsqlitefunctions.so -lm

Regards, Fat jonnie

+1
source

Source: https://habr.com/ru/post/1499259/


All Articles