Compiling spellfix on macos - Error: Undefined symbols for architecture x86_64
(1) By Nat Taylor (ntaylor) on 2020-12-10 03:21:11 [link] [source]
I'm trying to follow the Compiling A Loadable Extension instructions to compile spellfix.c
but faced with the error Undefined symbols for architecture x86_64
(full output below)
Then I tried adding -l sqlite3
(gcc -g -fPIC -dynamiclib spellfix.c -l sqlite3 -o spellfix.dylib -v
) and it compiled, but when I load it (.load ./spellfix.dylib
) then sqlite3 crashes with
sqlite> .load ./spellfix.dylib
zsh: segmentation fault sqlite3 items.db
Am I on the right track? Any tips? I'm on MacOS 11.0.1. Thank you.
gcc -g -fPIC -dynamiclib spellfix.c -o spellfix.dylib -v
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: x86_64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx11.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name spellfix.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=11.0 -target-cpu penryn -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=lldb -target-linker-version 609.6 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -fdebug-compilation-dir /Users/ntaylor/Downloads/datalist -ferror-limit 19 -fmessage-length 238 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-11.0.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/lx/0l9_67_x0xjcrn2g4p6s4j_40000gq/T/spellfix-f9aba8.o -x c spellfix.c
clang -cc1 version 12.0.0 (clang-1200.0.32.27) default target x86_64-apple-darwin20.1.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -dylib -arch x86_64 -platform_version macos 11.0.0 11.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o spellfix.dylib -L/usr/local/lib /var/folders/lx/0l9_67_x0xjcrn2g4p6s4j_40000gq/T/spellfix-f9aba8.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_sqlite3_bind_text", referenced from:
_spellfix1RunQuery in spellfix-f9aba8.o
"_sqlite3_bind_value", referenced from:
_spellfix1FilterForFullScan in spellfix-f9aba8.o
"_sqlite3_column_bytes", referenced from:
_editDist3ConfigLoad in spellfix-f9aba8.o
_spellfix1RunQuery in spellfix-f9aba8.o
"_sqlite3_column_int", referenced from:
_editDist3ConfigLoad in spellfix-f9aba8.o
_spellfix1RunQuery in spellfix-f9aba8.o
"_sqlite3_column_int64", referenced from:
_spellfix1Rowid in spellfix-f9aba8.o
_spellfix1RunQuery in spellfix-f9aba8.o
"_sqlite3_column_text", referenced from:
_editDist3ConfigLoad in spellfix-f9aba8.o
_spellfix1RunQuery in spellfix-f9aba8.o
"_sqlite3_column_value", referenced from:
_spellfix1Column in spellfix-f9aba8.o
"_sqlite3_context_db_handle", referenced from:
_editDist3SqlFunc in spellfix-f9aba8.o
"_sqlite3_create_function", referenced from:
_spellfix1Register in spellfix-f9aba8.o
"_sqlite3_create_function_v2", referenced from:
_editDist3Install in spellfix-f9aba8.o
"_sqlite3_create_module", referenced from:
_spellfix1Register in spellfix-f9aba8.o
"_sqlite3_declare_vtab", referenced from:
_spellfix1Init in spellfix-f9aba8.o
"_sqlite3_exec", referenced from:
_spellfix1DbExec in spellfix-f9aba8.o
"_sqlite3_finalize", referenced from:
_spellfix1ResetCursor in spellfix-f9aba8.o
_spellfix1FilterForMatch in spellfix-f9aba8.o
_editDist3ConfigLoad in spellfix-f9aba8.o
"_sqlite3_free", referenced from:
_transliterateSqlFunc in spellfix-f9aba8.o
_phoneticHashSqlFunc in spellfix-f9aba8.o
_editDist3Install in spellfix-f9aba8.o
_editdist1 in spellfix-f9aba8.o
_spellfix1Close in spellfix-f9aba8.o
_spellfix1Column in spellfix-f9aba8.o
_spellfix1Update in spellfix-f9aba8.o
...
"_sqlite3_last_insert_rowid", referenced from:
_spellfix1Update in spellfix-f9aba8.o
"_sqlite3_malloc64", referenced from:
_editDist3Install in spellfix-f9aba8.o
_transliterate in spellfix-f9aba8.o
_editdist1 in spellfix-f9aba8.o
_phoneticHash in spellfix-f9aba8.o
_spellfix1Open in spellfix-f9aba8.o
_spellfix1Init in spellfix-f9aba8.o
_spellfix1FilterForMatch in spellfix-f9aba8.o
...
"_sqlite3_mprintf", referenced from:
_spellfix1Update in spellfix-f9aba8.o
_spellfix1Rename in spellfix-f9aba8.o
_spellfix1Init in spellfix-f9aba8.o
_spellfix1Dequote in spellfix-f9aba8.o
_spellfix1FilterForMatch in spellfix-f9aba8.o
_spellfix1FilterForFullScan in spellfix-f9aba8.o
_editDist3ConfigLoad in spellfix-f9aba8.o
...
"_sqlite3_prepare", referenced from:
_editDist3ConfigLoad in spellfix-f9aba8.o
"_sqlite3_prepare_v2", referenced from:
_spellfix1FilterForMatch in spellfix-f9aba8.o
_spellfix1FilterForFullScan in spellfix-f9aba8.o
"_sqlite3_realloc64", referenced from:
_spellfix1ResizeCursor in spellfix-f9aba8.o
_editDist3ConfigLoad in spellfix-f9aba8.o
_editDist3FromStringNew in spellfix-f9aba8.o
_editDist3Core in spellfix-f9aba8.o
"_sqlite3_reset", referenced from:
_spellfix1RunQuery in spellfix-f9aba8.o
"_sqlite3_result_error", referenced from:
_editdistSqlFunc in spellfix-f9aba8.o
"_sqlite3_result_error_code", referenced from:
_editDist3SqlFunc in spellfix-f9aba8.o
"_sqlite3_result_error_nomem", referenced from:
_transliterateSqlFunc in spellfix-f9aba8.o
_editdistSqlFunc in spellfix-f9aba8.o
_phoneticHashSqlFunc in spellfix-f9aba8.o
_editDist3SqlFunc in spellfix-f9aba8.o
"_sqlite3_result_int", referenced from:
_editdistSqlFunc in spellfix-f9aba8.o
_scriptCodeSqlFunc in spellfix-f9aba8.o
_spellfix1Column in spellfix-f9aba8.o
_editDist3SqlFunc in spellfix-f9aba8.o
"_sqlite3_result_null", referenced from:
_spellfix1Column in spellfix-f9aba8.o
"_sqlite3_result_text", referenced from:
_transliterateSqlFunc in spellfix-f9aba8.o
_phoneticHashSqlFunc in spellfix-f9aba8.o
_spellfix1Column in spellfix-f9aba8.o
"_sqlite3_result_value", referenced from:
_spellfix1Column in spellfix-f9aba8.o
"_sqlite3_step", referenced from:
_spellfix1Next in spellfix-f9aba8.o
_spellfix1FilterForFullScan in spellfix-f9aba8.o
_editDist3ConfigLoad in spellfix-f9aba8.o
_spellfix1RunQuery in spellfix-f9aba8.o
"_sqlite3_stricmp", referenced from:
_spellfix1Update in spellfix-f9aba8.o
"_sqlite3_user_data", referenced from:
_editDist3SqlFunc in spellfix-f9aba8.o
"_sqlite3_value_bytes", referenced from:
_transliterateSqlFunc in spellfix-f9aba8.o
_phoneticHashSqlFunc in spellfix-f9aba8.o
_scriptCodeSqlFunc in spellfix-f9aba8.o
_spellfix1Update in spellfix-f9aba8.o
_spellfix1FilterForMatch in spellfix-f9aba8.o
_editDist3SqlFunc in spellfix-f9aba8.o
"_sqlite3_value_int", referenced from:
_spellfix1Update in spellfix-f9aba8.o
_spellfix1FilterForMatch in spellfix-f9aba8.o
_editDist3SqlFunc in spellfix-f9aba8.o
"_sqlite3_value_int64", referenced from:
_spellfix1Update in spellfix-f9aba8.o
"_sqlite3_value_text", referenced from:
_transliterateSqlFunc in spellfix-f9aba8.o
_editdistSqlFunc in spellfix-f9aba8.o
_phoneticHashSqlFunc in spellfix-f9aba8.o
_scriptCodeSqlFunc in spellfix-f9aba8.o
_spellfix1Update in spellfix-f9aba8.o
_spellfix1FilterForMatch in spellfix-f9aba8.o
_editDist3SqlFunc in spellfix-f9aba8.o
...
"_sqlite3_value_type", referenced from:
_spellfix1Update in spellfix-f9aba8.o
"_sqlite3_vmprintf", referenced from:
_spellfix1DbExec in spellfix-f9aba8.o
"_sqlite3_vtab_config", referenced from:
_spellfix1Init in spellfix-f9aba8.o
"_sqlite3_vtab_on_conflict", referenced from:
_spellfix1GetConflict in spellfix-f9aba8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(2.1) By Dan Kennedy (dan) on 2020-12-10 11:40:03 edited from 2.0 in reply to 1 [source]
The same recipe works here (older system though - "Apple LLVM version 10.0.1 (clang-1001.0.46.4)").
spellfix1RunQuery() should not be invoking sqlite3_bind_text() directly in a loadable extension:
"_sqlite3_bind_text", referenced from:
_spellfix1RunQuery in spellfix-f9aba8.o
It should be calling it via a macro defined in included file sqlite3ext.h:
#define sqlite3_bind_text sqlite3_api->bind_text
If you figure out why this macro doesn't seem to be defined when spellfix1RunQuery() is compiled, things will probably become clear.
(3) By Nat Taylor (ntaylor) on 2020-12-16 04:29:42 in reply to 2.1 [link] [source]
I revisited this and got it to compile with the following:
gcc -g -O2 -shared -fPIC -I ../../../build -o spellfix ./spellfix.c