Skip to content

Instantly share code, notes, and snippets.

@aaronpk
Last active September 20, 2024 23:38
Show Gist options
  • 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!

@Tybion
Copy link

Tybion commented Sep 12, 2024

Sorry, after upgrading GRDB my code stopped working, and I had to fix it quickly, so I reverted my code to the sqlite3 code that I have listed above.

@vdshko
Copy link

vdshko commented Sep 12, 2024

@Tybion Do you still have these generated libs? Can you share it, please? Maybe, if I can compare yours and mine I will find the solution.

@Tybion
Copy link

Tybion commented Sep 12, 2024

I am travelling, only have a phone, but my working code was based completely on the sample code above.

@vdshko
Copy link

vdshko commented Sep 20, 2024

It took some time to find a solution, but it was worth it.
I wrote an article with explanations to help developers like us avoid the same struggle.
Long story short - for proper work SpatiaLite needs to be initialized on the C level.

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