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.
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?
Answer: How to get Sqlite going with D on 64bit Ubuntu
-
install sqlite dev
sudo apt-get install libsqlite3-dev -
compile
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 switch was needed because of sqlite3 linking problems
You can use the binding with an available
sqlitelibrary (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-llibraryto compiler flags. The same here —import, and a link directive.EDIT:
On Ubuntu you can install precompiled
sqliteusing the following command:Also, see http://prowiki.org/wiki4d/wiki.cgi?DatabaseBindings#SQLite for some other
sqlitebinding variants.