如何将SQlite扩展源文件链接到iPhone的Xcode? [英] How to link a SQlite Extension Source File into Xcode for iPhone?

查看:150
本文介绍了如何将SQlite扩展源文件链接到iPhone的Xcode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iPhone Xcode项目中为Sqlite使用静态链接库。我现在正试图在这个项目中包含一个.c扩展名到Sqlite。但是,我在构建中使用Sqlite时遇到问题SEE扩展。

I use a statically linked library for Sqlite in an iPhone Xcode project. I am now trying to include a .C extension to Sqlite in this project. However, I am having trouble making the Sqlite in the build SEE the extension.

静态链接的Sqlite库工作正常。此.C扩展也适用于我的桌面,并在Xcode中作为静态链接库构建良好。但是,调用它时定义的自定义函数会丢失。

The statically linked Sqlite library works fine. Also the .C extension works on my desktop, and builds fine as a statically linked library in Xcode. However, the custom functions it defines are missing when called.

例如,我加载了扩展名,没有错误。

For example, I load the extension as so with no errors.

SELECT load_extension('extension_name.so');

但是当我尝试调用扩展中定义的函数时,我收到此消息

But when I try to call a function defined in the extension, I get this message

DB Error: 1 "no such function: custom_function"

有没有人知道将Sqlite扩展链接到Xcode项目?

Does anyone know much about linking a Sqlite extension into an Xcode project?

推荐答案

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.

希望这有帮助。

这篇关于如何将SQlite扩展源文件链接到iPhone的Xcode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆