www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compiling with SQLite

reply "impatient-dev" <impatient-dev example.com> writes:
I'm new to D, and I'm trying to use SQLite, but I can't get this 
basic program to compile:

import etc.c.sqlite3 : sqlite3_open;

void main(string[] args){
	sqlite3_open("test.sqlite", null);
}

When compiling with DMD v2.066.1, I get this error:

test.o: In function `_Dmain':
test.d:(.text._Dmain+0x2f): undefined reference to `sqlite3_open'
collect2: ld returned 1 exit status
--- errorlevel 1

Any idea what I'm doing wrong? I'm on Ubuntu 12.04 64-bit, but I 
doubt that matters. I've tried a couple alternatives, but they 
didn't work either.
Nov 17 2014
next sibling parent "impatient-dev" <impatient-dev example.com> writes:
Addendum: I'm using DDT for Eclipse, and the names I'm using come 
up in its autocomplete. They also appear at 
http://dlang.org/phobos/etc_c_sqlite3.html, which is why I'm 
stumped. I get what the error means, but I don't understand why 
it's occurring.
Nov 17 2014
prev sibling parent reply "uri" <uri gmail.com> writes:
On Tuesday, 18 November 2014 at 01:14:26 UTC, impatient-dev wrote:
 I'm new to D, and I'm trying to use SQLite, but I can't get 
 this basic program to compile:

 import etc.c.sqlite3 : sqlite3_open;

 void main(string[] args){
 	sqlite3_open("test.sqlite", null);
 }

 When compiling with DMD v2.066.1, I get this error:

 test.o: In function `_Dmain':
 test.d:(.text._Dmain+0x2f): undefined reference to 
 `sqlite3_open'
 collect2: ld returned 1 exit status
 --- errorlevel 1

 Any idea what I'm doing wrong? I'm on Ubuntu 12.04 64-bit, but 
 I doubt that matters. I've tried a couple alternatives, but 
 they didn't work either.
Are you linking with libsqlite3.a? For example: $ dmd prog.d -L-lsqlite3
Nov 17 2014
parent reply "impatient-dev" <impatient-dev example.com> writes:
On Tuesday, 18 November 2014 at 03:41:42 UTC, uri wrote:
 Are you linking with libsqlite3.a?

 For example:

 $ dmd prog.d -L-lsqlite3
That worked, thanks. I didn't know you had to anything special to link with code in the standard library; is there documentation for this somewhere? Also, is there a way I could make SQLite work with DUB rather than building manually? The command-line help and web page don't seem to mention this anywhere.
Nov 17 2014
parent "tcak" <tcak gmail.com> writes:
On Tuesday, 18 November 2014 at 05:06:59 UTC, impatient-dev wrote:
 On Tuesday, 18 November 2014 at 03:41:42 UTC, uri wrote:
 Are you linking with libsqlite3.a?

 For example:

 $ dmd prog.d -L-lsqlite3
That worked, thanks. I didn't know you had to anything special to link with code in the standard library; is there documentation for this somewhere?
D doesn't have the whole implementation of SQLite. It is implemented as a library, and the sqlite3 module hooks up to library's functions. So, you should give your program the library ie. implementation of SQLite.
Nov 18 2014