What is the easiest way to use Sqlite in a D program on Ubuntu?

I guess using the phobos.etc.c.sqlite3 binding. Compiling sqlite3.c using the C compiler to create the .o file and then link it to my program.

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

Or is there some other easier way?

Answer: How to get Sqlite with D on 64-bit 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 was needed due to sqlite3 problems

+6
source share
3 answers

You can use the binding with the available sqlite library (corresponding version, of course), without having to manually compile it into an object file. Like what you would do in C: you would #include <headers> and add -llibrary to the compiler flags. The same thing here is import and the link directive.

EDIT:

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

 sudo apt-get install libsqlite3-dev 

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

+3
source

As long as you have the sqlite3 development package installed, you can simply call dmd test.d -L-lsqlite3 - there is no need for an absolute path.

A good alternative is lib pragma:

 pragma(lib, "sqlite3"); import std.stdio, std.string, etc.c.sqlite3; void main () { sqlite3* db; auto ret = sqlite3_open (toStringz("mydb.s3db"), &db); writeln (ret); } 

With this, you can simply say dmd test.d

I cannot reproduce your problem using -ldl , but this can also be added as a pragma directive.

+9
source

Recent phobos contain a completely updated SQLite binding.

See phobos / etc / c / sqlite3.d

+1
source

Source: https://habr.com/ru/post/892569/


All Articles