Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Last active May 2, 2024 01:11
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save aaronpk/0252426d5161bc9650d8 to your computer and use it in GitHub Desktop.
Save aaronpk/0252426d5161bc9650d8 to your computer and use it in GitHub Desktop.
How to compile and install spatialite on iOS

Spatialite for iOS

Install compiler dependencies

brew install automake autoconf libtool libxml2 pkg-config
brew link libxml2

Build libspatialite

git clone https://github.com/gstf/libspatialite-ios.git
cd libspatialite-ios
make

The result is a folder, lib, containing several .a files, as well as an include folder containing many .h files.

Create a new XCode project

Copy the libspatialite binaries and "include" folder into a folder named "libspatialite" in the XCode project folder.

filesystem

In the XCode project's "Build Settings", you'll need to set the library and header search paths:

Library Search Paths: $(PROJECT_DIR)/AppName/libspatialite Header Search Paths: $(PROJECT_DIR)/AppName/libspatialite/include

search paths

Drag the .a files into your project.

From the "Build Phases" window, add the following to the section "Link Binary With Libraries":

  • libz.dylib
  • libxml2.2.dylib
  • libc++.dylib
  • libcharset.1.0.0.dylib
  • libiconv.dylib

XCode Project

Now you should be able to use spatialite! To test if everything worked, just make your AppDelegate output the spatialite version.

Add the following to AppDelegate.m

#include <sqlite3.h>
#include <spatialite/gaiageo.h>
#include <spatialite.h>

In your application:didFinishLaunchingWithOptions: method, add:

spatialite_init (0);
printf("Spatialite version: %s\n", spatialite_version());

Compile and run and you should see the version output in the console!

@ali711
Copy link

ali711 commented Mar 20, 2024

@smbkr @mrclayman i have seen both of you guys have worked on building spatialite i tried both of the solutions.
I built spatialite 4.4.0 using https://github.com/smbkr/libspatialite-ios/blob/master/Makefile and
Last i used was https://github.com/mrclayman/libspatialite-ios/blob/libspatialite-5/Makefile

In both of the solutions base spatialite functions works fine in IOS but functions which require geos or proj or rtree does not work.(i also built another with rttopo for test purpose by manually disabeling GEOSContext_setErrorMessageHandler_r() check and it was built successfully)
For example ST_IsValid , IsValidReason , ST_Within , ST_Overlaps etc. ST_Within does not filter any feature. ST_IsValid always returns -1 even when i tried it on SELECT ST_IsValid(ST_GeomFromText('POINT(15.785 21.713)')).
I believe there is some library communication problem or might need to update build process.
I have posted complete problem detail here as well
https://stackoverflow.com/questions/78187601/st-within-st-isvalid-or-any-other-geos-or-rtreetopo-related-function-not-working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment