且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将SQlite扩展源文件链接到iPhone的Xcode?

更新时间:2023-02-01 12:38:41

As @jbworld说你不能在iPhone上加载动态库,所以这个链接应该在编译时静态创建。在阅读spatialite的代码(这是一个SQLite扩展)时,我发现了这种调用:

As said by @jbworld you cannot load dynamic libraries on the iPhone, so this link should be made statically, at compilation time. While reading at the code of spatialite (that's an SQLite extension), I found that kind of invocation:

void spatialite_init (int verbose) {
/* used when SQLite initializes SpatiaLite via statically linked lib */
    sqlite3_auto_extension ((void (*)(void)) init_static_spatialite);
}

init_static_spatialite 代码:

static void init_static_spatialite (sqlite3 * db, char **pzErrMsg,
            const sqlite3_api_routines * pApi)
{
    SQLITE_EXTENSION_INIT2 (pApi);
/* setting the POSIX locale for numeric */
    setlocale (LC_NUMERIC, "POSIX");
    *pzErrMsg = NULL;
    sqlite3_create_function (db, "spatialite_version", 0, SQLITE_ANY, 0,
                             fnct_spatialite_version, 0, 0);
    sqlite3_create_function (db, "proj4_version", 0, SQLITE_ANY, 0,
                             fnct_proj4_version, 0, 0);
    sqlite3_create_function (db, "geos_version", 0, SQLITE_ANY, 0,
                             fnct_geos_version, 0, 0);
    sqlite3_create_function (db, "GeometryConstraints", 3, SQLITE_ANY, 0,
                             fnct_GeometryConstraints, 0, 0);
    sqlite3_create_function (db, "CheckSpatialMetaData", 0, SQLITE_ANY, 0,
                             fnct_CheckSpatialMetaData, 0, 0);
...

所以看起来如果 sqlite_auto_extension 使您可以静态链接扩展名。 文档似乎确认:

So it looks like if the sqlite_auto_extension enables you to statically link an extension. The documentation seems to confirm that:


可以在程序启动时调用此API,以便注册一个或多个可用于所有新数据库连接的静态链接扩展。

"This API can be invoked at program startup in order to register one or more statically linked extensions that will be available to all new database connections."

然后,在运行时,对于spatialite,我只需要调用 spatialite_init(0)来获得扩展名

Then, at runtime, for spatialite, I just have to invoke the spatialite_init(0) to get the extension up and running.

希望这有帮助。