Install Spatialite on OS X

378 views
Skip to first unread message

Andrii Kovalov

unread,
Mar 17, 2015, 6:58:07 PM3/17/15
to spatiali...@googlegroups.com
Hello, I have problems installing spatialite on my OS X Yosemite

Firstly I installed sqlite 3.8.7.4 
Then I downloaded sources for libspatialite-4.2.0.zip and spatialite-tools-4.2.0.zip
I managed to install successfully libspatialite but when I try to build and install spatialite tools I get following error

sudo make

/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am

gcc -DHAVE_CONFIG_H -I.  -g -O2 -I.   -g -O2 -MT shell.o -MD -MP -MF .deps/shell.Tpo -c -o shell.o shell.c

mv -f .deps/shell.Tpo .deps/shell.Po

/bin/sh ./libtool  --tag=CC   --mode=link gcc  -g -O2   -o spatialite shell.o -L/usr/local/lib -lspatialite -lsqlite3 -lm -lz -L/usr/local/Cellar/freexl/1.0.0g/lib -lfreexl -lm -lreadline -lcurses  -lproj -lexpat -L/usr/local/Cellar/geos/3.4.2/lib -lgeos_c

libtool: link: gcc -g -O2 -o spatialite shell.o  -L/usr/local/lib /usr/local/lib/libspatialite.dylib -L/usr/local/Cellar/geos/3.4.2/lib -lxml2 -lpthread -ldl -liconv /usr/local/lib/libsqlite3.dylib -lz -L/usr/local/Cellar/freexl/1.0.0g/lib -lfreexl -lreadline -lcurses /usr/local/Cellar/proj/4.8.0/lib/libproj.dylib -lm -lexpat -lgeos_c

Undefined symbols for architecture x86_64:

  "_sqlite3_enable_load_extension", referenced from:

      _open_db in shell.o

  "_sqlite3_load_extension", referenced from:

      _do_meta_command in shell.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[1]: *** [spatialite] Error 1

make: *** [all] Error 2


Please point me how to fix this and thank you for your time.

a.fu...@lqt.it

unread,
Mar 18, 2015, 7:39:50 AM3/18/15
to spatiali...@googlegroups.com
On Tue, 17 Mar 2015 15:58:06 -0700 (PDT), Andrii Kovalov wrote:
> Hello, I have problems installing spatialite on my OS X Yosemite
>
> Firstly I installed sqlite 3.8.7.4
> Then I downloaded sources for libspatialite-4.2.0.zip and
> spatialite-tools-4.2.0.zip
> I managed to install successfully libspatialite but when I try to
> build and install spatialite tools I get following error
>
> Undefined symbols for architecture x86_64:
>
> "_sqlite3_enable_load_extension", referenced from:
>
> _open_db in shell.o
>
> "_sqlite3_load_extension", referenced from:
>
> _do_meta_command in shell.o
>

Hi Andrii,

your libsqlite3 was clearly built by completely disabling
any support for dynamically loading external extensions.

solution: build and install by yourself a canonical libsqlite3.

alternative solution: install both sqlite and spatialite
for MacPorts or HomeBrew.

bye Sando

Andrii Kovalov

unread,
Mar 18, 2015, 8:12:03 AM3/18/15
to spatiali...@googlegroups.com
Thank you for your response.
I want to clarify that I build and install sqlite manually from sources.
How can I assure that I enable dynamic loading of external extensions?

a.fu...@lqt.it

unread,
Mar 18, 2015, 8:57:19 AM3/18/15
to spatiali...@googlegroups.com
On Wed, 18 Mar 2015 05:12:03 -0700 (PDT), Andrii Kovalov wrote:
> Thank you for your response.
> I want to clarify that I build and install sqlite manually from
> sources.
> How can I assure that I enable dynamic loading of external
> extensions?
>

Hi Andrii,

if you've built libsqlite by simply applying its standard configuration
you've surely enabled dynamic extensions support, because this is the
default.

you are possibly facing a different issue: Apple ships its own
system version of libsqlite3, and this is surely disabling dynamic
extensions because this is required the Apple's security standards.
so you have now installed two different versions of libsqlite3,
one supporting extensions and one not.

under such a configuration you necessarily have to instruct
./configure so to point to the "right" version; this is usually
accomplished by setting a couple of environment variables:

export "CFLAGS=-I/usr/local/include"
export "LDFLAGS-L/usr/local/lib"
./configure

please note: "/usr/local/" is the default location for any
custom-built package on Linux; on MacOsX it's probably renamed
as "/opt/local/", anyway you can easily check for the real name.

bye Sandro

Andrii Kovalov

unread,
Mar 18, 2015, 8:57:31 AM3/18/15
to spatiali...@googlegroups.com
I investigated a bit more and discovered that I can control this with 

SQLITE_OMIT_LOAD_EXTENSION property in Makefile

So I changed it to:
# Enable/disable loadable extensions, and other optional features
# based on configuration. (-DSQLITE_OMIT*, -DSQLITE_ENABLE*).  
# The same set of OMIT and ENABLE flags should be passed to the 
# LEMON parser generator and the mkkeywordhash tool as well.
OPT_FEATURE_FLAGS = -DSQLITE_OMIT_LOAD_EXTENSION=0

But unfortunately I still get this error:

Undefined symbols for architecture x86_64:

  "_sqlite3_enable_load_extension", referenced from:

      _open_db in shell.o

  "_sqlite3_load_extension", referenced from:

      _do_meta_command in shell.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[1]: *** [spatialite] Error 1

make: *** [all] Error 2

So as I understand for some reason my sqlite library still doesn't allow to load external extensions?

On Wednesday, March 18, 2015 at 1:39:50 PM UTC+2, sandro furieri wrote:

Andrii Kovalov

unread,
Mar 18, 2015, 8:59:52 AM3/18/15
to spatiali...@googlegroups.com
Thank you for you response, I will try it do as you suggested

Andrii Kovalov

unread,
Mar 18, 2015, 9:34:52 AM3/18/15
to spatiali...@googlegroups.com
Thank you for you help, I really appreciate the time you spent helping me.
I think you are right about OS X provided sqlite library which interferers with sqlite library that I build manually.
So when I specify path explicitly it seems to work just fine.
So I followed your suggestions and tried following:

user@SQLite-f66f7a17$ export "CFLAGS=-I/usr/local/include"

user@SQLite-f66f7a17$ export "LDFLAGS-L/usr/local/lib"

user@SQLite-f66f7a17$ ./configure --enable-load-extension

user@SQLite-f66f7a17$ sudo make clean 

user@SQLite-f66f7a17$ sudo make

In the output I can see couple of warnings:

ld: warning: invalid -install_name (/usr/local/lib/libsqlite3.0.dylib) in dependent dylib (./.libs/libsqlite3.dylib). Dylibs/frameworks which might go in dyld shared cache cannot link with dylibs that won't be in the shared cache

warning: no debug symbols in executable (-arch x86_64)

user@SQLite-f66f7a17$ sudo make install

user@SQLite-f66f7a17$ sqlite3 -version 

3.8.7.4 2014-12-09 01:34:36 f66f7a17b78ba617acde90fc810107f34f1a1f2e

user@SQLite-f66f7a17$ which sqlite3 

/usr/local/bin/sqlite3

Now go to spatialite sources and run:

us...@spatialite-tools-4.2.0$ make clean

us...@spatialite-tools-4.2.0$ make 

us...@spatialite-tools-4.2.0$ sudo make install

us...@spatialite-tools-4.2.0$ spatialite -version

3.8.7.4 2014-12-09 01:34:36 f66f7a17b78ba617acde90fc810107f34f1a1f2e

us...@spatialite-tools-4.2.0$ cd ~/Temp/

user@Temp$ spatialite test.sqlite

SpatiaLite version ..: 4.2.0 Supported Extensions:

- 'VirtualShape' [direct Shapefile access]

- 'VirtualDbf' [direct DBF access]

- 'VirtualXL' [direct XLS access]

- 'VirtualText' [direct CSV/TXT access]

- 'VirtualNetwork' [Dijkstra shortest path]

- 'RTree' [Spatial Index - R*Tree]

- 'MbrCache' [Spatial Index - MBR cache]

- 'VirtualSpatialIndex' [R*Tree metahandler]

- 'VirtualXPath' [XML Path Language - XPath]

- 'VirtualFDO' [FDO-OGR interoperability]

- 'VirtualGPKG' [OGC GeoPackage interoperability]

- 'VirtualBBox' [BoundingBox tables]

- 'SpatiaLite' [Spatial SQL - OGC]

PROJ.4 version ......: Rel. 4.8.0, 6 March 2012

GEOS version ........: 3.4.2-CAPI-1.8.2 r3921

TARGET CPU ..........: x86_64-apple-darwin14.1.0

the SPATIAL_REF_SYS table already contains some row(s)

SQLite version ......: 3.8.7.4

Enter ".help" for instructions

SQLite version 3.8.7.4 2014-12-09 01:34:36

Michael Draper

unread,
Feb 1, 2018, 3:10:30 AM2/1/18
to SpatiaLite Users
I'm in the same boat as the original poster. Following the identical steps:
 sqlite3 was correctly installed (3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2171d)
 spatialite was correctly installed (3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2171d)

However when I run:  spatialite test.sqlite
I receive Segmentation Fault: 11 

A file is generated but I'm not able to interact with the database at all :( 

I don't know how to debug a g++ segmentation fault so I can't help with what lines of code are failing, but I am running MacOS X High Sierra
Reply all
Reply to author
Forward
0 new messages