Compiling SpatiaLite for the iPhone

369 views
Skip to first unread message

Lionel Gueganton

unread,
Aug 5, 2009, 4:00:10 PM8/5/09
to SpatiaLite Users
Hello,
I just came accross the SpatiaLite project and it looked quite
interesting to me.
I've seen this post about the iPhone compilation :
http://groups.google.com/group/spatialite-users/browse_thread/thread/f3b5941da7eded8d
but as I don't manage to get it compiled and I don't have the "reply
to group" button (just reply to author ? :/), I'm starting a new
thread....
I downloaded the C Source code (amalgation) from here
http://www.gaia-gis.it/spatialite/amalgamation.html
and then I tried to setup an XCode project (to generate a static lib
or just embed the source code in my application project directly, I
don't have any prefered solution).
I added the 2 .c sources files (spatialite.c and sqlite3.c) to my
project, added the 2 pre processors macros OMIT_PROJ=1 OMIT_GEOS=1
(for now I just try to get the smallest part as possible) and then
compiled it.
When I'm building all for the iPhone Simulator, it builds properly (I
didn't try to run it however) but when I try to build it for the
device, the import #include <localcharset.h> is not resolved . I try
to google it in order to get the right library to be imported in the
project but wasn't able to get it :(
Janne, as you said you've been able to get it running on the iPhone,
maybe have you any hint to my issue regarding this import ? :/ Which
library did you had to get it running? (or did you add any other
source code directly ?)
Thanks for your help,
Best Regards,
Lionel.

Lionel Gueganton

unread,
Aug 5, 2009, 4:26:54 PM8/5/09
to SpatiaLite Users
Sorry, just some more information: the build failed at line 77 of
spacialite.c

/* <localcharset.h> isn't supported on OSGeo4W */
/* applying a tricky workaround to fix this issue */
extern const char * locale_charset (void);
#else /* sane Windows - not OSGeo4W */

***here**** :/
#include <localcharset.h>


#endif /* end localcharset */
#else /* not WINDOWS */
#ifdef __APPLE__
#include <iconv.h>
#include <localcharset.h>

On Aug 5, 10:00 pm, Lionel Gueganton <lionel.guegan...@gmail.com>
wrote:
> Hello,
> I just came accross the SpatiaLite project and it looked quite
> interesting to me.
> I've seen this post about the iPhone compilation :http://groups.google.com/group/spatialite-users/browse_thread/thread/...
> but as I don't manage to get it compiled and I don't have the "reply
> to group" button (just reply to author  ? :/), I'm starting a new
> thread....
> I downloaded the C Source code (amalgation)  from herehttp://www.gaia-gis.it/spatialite/amalgamation.html

janne kovanen

unread,
Aug 6, 2009, 4:11:53 AM8/6/09
to spatiali...@googlegroups.com
Hi Lionel,

I did not use localcharset, instead, this error can be managed by simply adding iconv to the iPhone build. And do this both for the simulator and actual device ;)

Cheers,
Janne

Lionel Gueganton

unread,
Aug 7, 2009, 8:07:33 AM8/7/09
to SpatiaLite Users
Hi Janne,
Thanks for your help, I've managed to get it running on both iPhone
and simulator. I've been able to invoke the spatiallite_version() and
it returned me 2.3.1.
I think I'm on the right track ;)
However, I've changed a little bit the way #ifdef are organized, and
the typedef as well (sqlite3 and sqlite3_int64 are not in the
spacialite.h but are used in there, so why do they only appear in
the .c ? :( )

Here's the way I manage to get it running, it does not look "academic"
to me so maybe you achieved it a better way than me.
Create a new XCode project
Add spatialite.h spatialite.c sqlite.c to it.
Move the typedef for
typedef struct sqlite3 sqlite3;
#ifdef SQLITE_INT64_TYPE
typedef SQLITE_INT64_TYPE sqlite_int64;
typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
#elif defined(_MSC_VER) || defined(__BORLANDC__)
typedef __int64 sqlite_int64;
typedef unsigned __int64 sqlite_uint64;
#else
typedef long long int sqlite_int64;
typedef unsigned long long int sqlite_uint64;
#endif
typedef sqlite_int64 sqlite3_int64;
typedef sqlite_uint64 sqlite3_uint64;

from the .c to the .h (they're used in the .h so I don't really
understand why they're only defined in the .c :/) In the end I just
import the .h from my app delegate.

Comment some ifdef in the .c in order to get the preprocessor getting
all appropriatly...
#if defined(__MINGW32__) || defined(_WIN32)
#define LIBICONV_STATIC
#include <iconv.h>
#define LIBCHARSET_STATIC
#ifdef _MSC_VER
/* <localcharset.h> isn't supported on OSGeo4W */
/* applying a tricky workaround to fix this issue */
extern const char * locale_charset (void);
#else /* sane Windows - not OSGeo4W */
#include <localcharset.h>
#endif /* end localcharset */
#else /* not WINDOWS */
//#ifdef __APPLE__
//#include <iconv.h>
//#include <localcharset.h>
//#else /* not Mac OsX */
#include <iconv.h>
#include <langinfo.h>
#endif
//#endif

Include libiconv.dylib libcharset.dylib from
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/
usr/lib/

Then it works... I've been able to open the DB test-2.3.sqlite from
the tutorial, so now I'm starting to play with the SQL requests.

Isn't there any best way to get this running ? My comments and changes
in the source code don't satisfy me and I was wondering if you hadn't
any best way to achieve this ? (so that when I change version, I don't
have to change each time the source code :/)

Thanks for your help anyway, I can now start to really play with the
library :p
My goal is to get some Open Street map data imported correctly into
spatialite. It seems to be feasible from what I've seen here :
http://www.camptocamp.com/fr/blog/2009/02/kiss-spatialite-in-5-minutes/
The import is achieved with the GUI but I suppose there a way to do it
programmatically ? (I'm not very familiar with the shapeFile format :/
any hint for the fastest / most elegant way to import OSM data from
within the code into spatialite ?)
I'll have a look at the source from the GUI tool....
Best regards
Lionel.

On Aug 6, 10:11 am, janne kovanen <janne.li...@gmail.com> wrote:
> Hi Lionel,
> I did not use localcharset, instead, this error can be managed by simply
> adding iconv to the iPhone build. And do this both for the simulator and
> actual device ;)
>
> Cheers,
> Janne
>
> On Wed, Aug 5, 2009 at 11:26 PM, Lionel Gueganton <
>
Reply all
Reply to author
Forward
0 new messages