Search code examples
macossqlitespatialite

How to load Spatialite SQLite extension on macOS


I am attempting to load the libspatialite extension in SQLite. As per the installation guide, I downloaded the latest libspatialite and moved the included libspatialite.1.1.3.dylib file to /usr/local/lib.

greg /usr/local/lib $ls | grep libspatialite
libspatialite.1.1.3.dylib

However, I was unable to load the extension.

sql> SELECT load_extension('libspatialite.1.1.3.dylib')
[2017-09-19 10:45:25] [1] [SQLITE_ERROR] SQL error or missing database (dlopen(libspatialite.1.1.3.dylib.dylib, 10): image not found)

I also tried storing libspatialite.1.1.3.dylib.dylib in the same directory as the sqlite file with no luck.

I have confirmed that enable_load_extension is true and I'm using DataGrip as my IDE. I have also quit DataGrip and rebooted to ensure any new binaries are collected. Am I missing something obvious?


Solution

  • As per this homebrew formula for libspatialite:

    New SQLite3 extension won't load via SELECT load_extension("mod_spatialite"); unless named mod_spatialite.dylib (should actually be mod_spatialite.bundle). See: https://groups.google.com/forum/#!topic/spatialite-users/EqJAB8FYRdI

    So, if installing manually, you gonna need to rename the dynamic library file as per suggested. Or you can let Homebrew do the installation for you:

    brew install libspatialite