在Ubuntu的D程序中使用Sqlite的最简单方法是什么? [英] What is the easiest way to use Sqlite in D program on Ubuntu?

查看:59
本文介绍了在Ubuntu的D程序中使用Sqlite的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 phobos.etc.c.sqlite3 绑定。使用C编译器编译sqlite3.c来创建.o文件,然后将其链接到我的程序。

I suppose using phobos.etc.c.sqlite3 binding. Compiling sqlite3.c using a C compiler to make a .o file and then link it with my program.

我应该使用哪个C编译器,以及哪些编译器标志?
是否可以一步将sqlite3.o与DMD链接,而无需分别调用链接器?

Which C compiler should I use, and what compiler flags? Is it possible link the sqlite3.o with DMD in one step, without calling linker separately?

还是还有其他更简单的方法?

Or is there some other even easier way?

答案:如何在64位Ubuntu上使Sqlite与D配合使用


  1. install sqlite dev sudo apt-get install libsqlite3-dev

编译 dmd test.d -L-ldl -L / usr / lib / x86_64-linux-gnu / libsqlite3.a

test.d

import std.stdio, std.string, etc.c.sqlite3;

void main () {
    sqlite3* db;
    auto ret = sqlite3_open (toStringz("mydb.s3db"), &db);
    writeln (ret);
}

-ldl开关是因为sqlite3链接问题

-ldl switch was needed because of sqlite3 linking problems

推荐答案

使用可用的 sqlite 库(当然是适当版本)进行绑定,而不必手动将其编译为目标文件。就像在C语言中所做的那样:您将 #include< headers> 并添加 -llibrary 到编译器标志。此处相同- import 和链接指令。

You can use the binding with an available sqlite library (of an appropriate version, certainly), without having to manually compile it to an object file. Just like what you would have done in C: you'd #include <headers> and add -llibrary to compiler flags. The same here — import, and a link directive.

编辑:

在Ubuntu上,您可以使用以下命令安装预编译的 sqlite

On Ubuntu you can install precompiled sqlite using the following command:

sudo apt-get install libsqlite3-dev

另外,请参见 http://prowiki.org/wiki4d/wiki.cgi?DatabaseBindings#SQLite 用于其他 sqlite 绑定变体。

Also, see http://prowiki.org/wiki4d/wiki.cgi?DatabaseBindings#SQLite for some other sqlite binding variants.

这篇关于在Ubuntu的D程序中使用Sqlite的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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