我正在尝试使用页面上的说明在 M1 笔记本电脑上构建 percentile sqlite 扩展:
gcc -g -fPIC -shared percentile.c -o percentile.so
但是,这会导致以下错误:
clang
是否可以使用 clang 构建 sqlite 扩展,或者我是否需要获得真正的 GCC 才能完成这项工作?
$ gcc -g -fPIC -shared percentile.c -o percentile.so
Undefined symbols for architecture arm64:
"_sqlite3_aggregate_context", referenced from:
_percentStep in percentile-a11598.o
_percentFinal in percentile-a11598.o
"_sqlite3_create_function", referenced from:
_sqlite3_percentile_init in percentile-a11598.o
_sqlite3_percentile_init in percentile-a11598.o
_sqlite3_percentile_init in percentile-a11598.o
"_sqlite3_free", referenced from:
_percentStep in percentile-a11598.o
_percentFinal in percentile-a11598.o
"_sqlite3_realloc64", referenced from:
_percentStep in percentile-a11598.o
"_sqlite3_result_double", referenced from:
_percentFinal in percentile-a11598.o
"_sqlite3_result_error", referenced from:
_percentStep in percentile-a11598.o
_percentStep in percentile-a11598.o
_percentStep in percentile-a11598.o
_percentStep in percentile-a11598.o
_percentStep in percentile-a11598.o
"_sqlite3_result_error_nomem", referenced from:
_percentStep in percentile-a11598.o
"_sqlite3_user_data", referenced from:
_percentStep in percentile-a11598.o
"_sqlite3_value_double", referenced from:
_percentStep in percentile-a11598.o
_percentStep in percentile-a11598.o
_percentStep in percentile-a11598.o
"_sqlite3_value_numeric_type", referenced from:
_percentStep in percentile-a11598.o
_percentStep in percentile-a11598.o
"_sqlite3_value_type", referenced from:
_percentStep in percentile-a11598.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
结尾:
.dylib
尽管它确实会产生警告
gcc -g -fPIC -dynamiclib -undefined suppress percentile.c -o percentile.dylib
,但比我聪明的人(有很多)可能能够提供帮助。
但是,当您尝试加载它时,如果您在ld: warning: -undefined suppress is deprecated
中使用Apple提供的
sqlite3
命令,则会失败。您可以通过运行来判断您正在使用哪一个:/usr/bin/sqlite3
当您尝试加载它时,您会得到:
type sqlite3
sqlite3 is /usr/bin/sqlite3
如果您随后检查Apple如何编译
sqlite> .load percentile
Error: unknown command or invalid arguments: "load". Enter ".help" for help
:
sqlite3
输出
sqlite3 :memory: 'select * from pragma_compile_options()'
您可以看到Apple不允许使用
ATOMIC_INTRINSICS=1
BUG_COMPATIBLE_20160819
CCCRYPT256
COMPILER=clang-15.0.0
DEFAULT_AUTOVACUUM
DEFAULT_CACHE_SIZE=2000
DEFAULT_CKPTFULLFSYNC
DEFAULT_FILE_FORMAT=4
DEFAULT_JOURNAL_SIZE_LIMIT=32768
DEFAULT_LOOKASIDE=1200,102
DEFAULT_MEMSTATUS=0
DEFAULT_MMAP_SIZE=0
DEFAULT_PAGE_SIZE=4096
DEFAULT_PCACHE_INITSZ=20
DEFAULT_RECURSIVE_TRIGGERS
DEFAULT_SECTOR_SIZE=4096
DEFAULT_SYNCHRONOUS=2
DEFAULT_WAL_AUTOCHECKPOINT=1000
DEFAULT_WAL_SYNCHRONOUS=1
DEFAULT_WORKER_THREADS=0
DQS=3
ENABLE_API_ARMOR
ENABLE_BYTECODE_VTAB
ENABLE_COLUMN_METADATA
ENABLE_DBPAGE_VTAB
ENABLE_DBSTAT_VTAB
ENABLE_EXPLAIN_COMMENTS
ENABLE_FTS3
ENABLE_FTS3_PARENTHESIS
ENABLE_FTS3_TOKENIZER
ENABLE_FTS4
ENABLE_FTS5
ENABLE_LOCKING_STYLE=1
ENABLE_MATH_FUNCTIONS
ENABLE_NORMALIZE
ENABLE_PREUPDATE_HOOK
ENABLE_RTREE
ENABLE_SESSION
ENABLE_SNAPSHOT
ENABLE_SQLLOG
ENABLE_STMT_SCANSTATUS
ENABLE_UNKNOWN_SQL_FUNCTION
ENABLE_UPDATE_DELETE_LIMIT
HAS_CODEC_RESTRICTED
HAVE_ISNAN
MALLOC_SOFT_LIMIT=1024
MAX_ATTACHED=10
MAX_COLUMN=2000
MAX_COMPOUND_SELECT=500
MAX_DEFAULT_PAGE_SIZE=8192
MAX_EXPR_DEPTH=1000
MAX_FUNCTION_ARG=127
MAX_LENGTH=2147483645
MAX_LIKE_PATTERN_LENGTH=50000
MAX_MMAP_SIZE=1073741824
MAX_PAGE_COUNT=1073741823
MAX_PAGE_SIZE=65536
MAX_SQL_LENGTH=1000000000
MAX_TRIGGER_DEPTH=1000
MAX_VARIABLE_NUMBER=500000
MAX_VDBE_OP=250000000
MAX_WORKER_THREADS=8
MUTEX_UNFAIR
OMIT_AUTORESET
OMIT_LOAD_EXTENSION <--- OOPS, ".load" not built in
STMTJRNL_SPILL=131072
SYSTEM_MALLOC
TEMP_STORE=1
THREADSAFE=2
USE_URI
命令。因此,您需要自己构建整个
/.load
,或者使用 homebrew安装其可执行文件:
sqlite3
然后你可以运行:
brew install sqlite
您将看到支持
/opt/homebrew/Cellar/sqlite/3.46.0/bin/sqlite3 :memory: 'select * from pragma_compile_options()'
命令。现在你可以做:
.load