asg017 / sqlite-vss

A SQLite extension for efficient vector search, based on Faiss!
MIT License
1.59k stars 59 forks source link

Mac M1 load error: dlsym(0x309d14370, sqlite3_vss_init): symbol not found #69

Closed cmcilvoy closed 1 year ago

cmcilvoy commented 1 year ago

M1 builds successfully but unable to load extension into SQLite version 3.36.0 Mac 13.4.1 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk Source package sqlite-vss-0.1.1-alpha.20

sqlite> .load /Users/user/Desktop/sqlite-vss/sqlite-vss/build_release/vss0.dylib Error: dlsym(0x309d14370, sqlite3_vss_init): symbol not found

polterguy commented 1 year ago

Do you get the same error if you're using the pre-built libraries?

cmcilvoy commented 1 year ago

Yes. Thanks for quick response.

(including .dylib it seems to duplicate) sqlite> .load /Users/user/Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64/vector0.dylib Error: dlopen(/Users/user/Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64/vector0.dylib.dylib, 0x000A): tried: '/Users/user/Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64/vector0.dylib.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Users/user/Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64/vector0.dylib.dylib' (no such file), '/U

(removing it seems to not like architecture) sqlite> .load /Users/user/Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64/vector0 Error: dlopen(/Users/user/Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64/vector0.dylib, 0x000A): tried: '/Users/user/Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64/vector0.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/user/Downloads/sqlite-vss-v0.1.1-alpha.20-loa

asg017 commented 1 year ago

Can you run uname -s -m on your machine and share what it prints out?

The mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64') message makes you think you might be on a x86_64 machine.

But regardless of that, if you build it yourself you shouldnt get the 'sqlite3_vss_init` symbol not found error. Can you also run:

nm -g /Users/user/Desktop/sqlite-vss/sqlite-vss/build_release/vss0.dylib | grep sqlite3_
cmcilvoy commented 1 year ago

uname -s -m Darwin arm64

nm -g /Users/cmcilvoy/Desktop/sqlite-vss/sqlite-vss/buildrelease/vss0.dylib | grep sqlite3 /Users/user/Desktop/sqlite-vss/sqlite-vss/build_release/vss0.dylib: no symbols

asg017 commented 1 year ago

hm alright that's really weird, a few questions:

cmcilvoy commented 1 year ago
asg017 commented 1 year ago

Ok so it seems like if you .load the vector0 file inside the Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64\ 2/ directory, it should work as expected. Be careful with the space (" ") character in that file path when you try, you can cd into that directory first and run sqlite3 with .load ./vector0 .

I suspect that .load ./vss0 in that directory should also work. If it doesn't, could you run nm -g vss0.dylib | grep sqlite3_ on that as well?

Re building yourself: if you did follow those steps then I have no idea why you get no symbols on there. You can also look in the sqlite-vss/dist/release directory, which should also have a vector0.dylib and vss0.dylib files. They're normally the same as the files in build_release, but something might've gotten corrupted

cmcilvoy commented 1 year ago

Ugh same incompatible message. Really weird.

@McLap > ~/Downloads/sqlite-vss-v0.1.1-alpha.20-loadable-macos-aarch64 /usr/local/opt/sqlite/bin/sqlite3 SQLite version 3.36.0 2021-06-18 18:36:39 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent database. sqlite> .load vector0 Error: dlopen(vector0.dylib, 0x000A): tried: 'vector0.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OSvector0.dylib' (no such file), '/usr/lib/vector0.dylib' (no such file, not in dyld cache), 'vector0.dylib' (mach-o file, but is an i sqlite> .load vector0.dylib Error: dlopen(vector0.dylib.dylib, 0x000A): tried: 'vector0.dylib.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSvector0.dylib.dylib' (no such file), '/usr/lib/vector0.dylib.dylib' (no such file, not in dyld cache), 'vector0.dylib.dylib' (no such file), '/usr/local/lib/vector0.dylib.dylib' (no such file) sqlite> .load vector0.dylib

@McLap > nm -g /Users/cmcilvoy/Desktop/sqlite-vss/sqlite-vss/dist/release/vector0.dylib /Users/cmcilvoy/Desktop/sqlite-vss/sqlite-vss/dist/release/vector0.dylib: no symbols @McLap > nm -g /Users/cmcilvoy/Desktop/sqlite-vss/sqlite-vss/dist/release/vss0.dylib /Users/cmcilvoy/Desktop/sqlite-vss/sqlite-vss/dist/release/vss0.dylib: no symbols

asg017 commented 1 year ago

Can you run file /usr/local/opt/sqlite/bin/sqlite3 ?

On my M1 mac, I installed sqlite3 with homebrew so it returns:

file /opt/homebrew/opt/sqlite/bin/sqlite3
/opt/homebrew/opt/sqlite/bin/sqlite3: Mach-O 64-bit executable arm64

I suspect that the 'vector0.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')) error may be coming from some MacOS Rosetta stuff that's trying to run x86_64 programs on your M1. So I'm thinking /usr/local/opt/sqlite/bin/sqlite3 may be a x86_64 build of sqlite3 and is causing this issue

cmcilvoy commented 1 year ago

That was it. I did a brew reinstall and its working properly. thanks!

asg017 commented 1 year ago

Glad to hear! Will add this problem to a "troubleshooting" doc in the near future