我正在尝试使用这个sqlite扩展来计算Sqlite dbs中的stdev,在Linux上,我用这个命令来编译lib
gcc -fPIC -lm -shared extension-functions.c -o libsqlitefunctions.so
但似乎.load命令不在sqlite .help命令列表中,我收到错误:
未知命令或无效参数:"load".输入".help"获取帮助
使用命令时会发生同样的事情:
sqlite> SELECT load_extension('./libsqlitefunctions.so');
Run Code Online (Sandbox Code Playgroud)
SQL错误:没有这样的函数: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
Run Code Online (Sandbox Code Playgroud)
但是在最新的Sqlite源代码中找不到"TCC + = -DSQLITE_OMIT_LOAD_EXTENSION = 1"这一行.
看起来configure已更新,但文档未更新。尝试
./configure --enable-dynamic-extensions
Run Code Online (Sandbox Code Playgroud)
参考的是configure源代码。进一步挖掘,看起来动态扩展是默认启用的。从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]
Run Code Online (Sandbox Code Playgroud)
所以我认为load是存在的。问题在于错误无效参数的第二部分。
原因似乎是您正在使用 Linux 指令。那是行不通的。Mac 通常没有.so文件,这是编译命令生成的文件。
编译和加载Mac动态库(可作为扩展加载)的方法就在这个位置。编译命令看起来像
gcc -bundle -fPIC -I/path-to-sqlite/sqlite3 -o filename.sqlext filename.c
Run Code Online (Sandbox Code Playgroud)
请注意-bundle和 ,-fPIC对于动态加载很重要,但您错过了。生成的文件名将为filename.sqlext,因此请在您的路径中使用它。
| 归档时间: |
|
| 查看次数: |
4451 次 |
| 最近记录: |