我正在尝试使用这个
sqlite extension来计算sqlite dbs中的stdev,在Linux上,我用这个命令来编译lib
gcc -fPIC -lm -shared extension-functions.c -o libsqlitefunctions.so
但似乎.load命令不在sqlite .help命令列表中,我收到错误:
unknown command or invalid arguments: “load”. Enter “.help” for help
使用命令时会发生同样的事情:
sqlite> SELECT load_extension('./libsqlitefunctions.so');
sql error: no such function: load_extension
我试着用这个指令来编译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
但是在最新的sqlite源代码中找不到“TCC = -DsqlITE_OMIT_LOAD_EXTENSION = 1”这一行.
解决方法
看起来配置已更新但不是文档.尝试
./configure --enable-dynamic-extensions
参考是配置源代码.进一步挖掘,默认情况下启用动态扩展.来自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]
原因似乎是你正在使用Linux指令.那不行. Mac通常没有.so文件,这是您的编译命令生成的.
编译和加载可作为扩展加载的Mac动态库的方法是在this location.编译命令看起来像
gcc -bundle -fPIC -I/path-to-sqlite/sqlite3 -o filename.sqlext filename.c
注意-bundle和-fPIC对动态加载很重要,但是你缺少它们.生成的文件名将是filename.sqlext,因此请在路径中使用它.