Jump to page: 1 2
Thread overview
embedding a library in Windows
Jan 30, 2017
Nestor
Jan 30, 2017
Kagamin
Jan 30, 2017
Nestor
Jan 30, 2017
Adam D. Ruppe
Jan 30, 2017
Nestor
Jan 30, 2017
Kagamin
Jan 30, 2017
kinke
Jan 30, 2017
Kagamin
Jan 30, 2017
biozic
Jan 30, 2017
biozic
Jan 30, 2017
Nestor
Jan 30, 2017
biozic
January 30, 2017
Hi,

In Windows, is it possible embed a dll library into an application (in this particular case, sqlite3.dll)? Notice I don't mean storing the resource in the application to extract it at runtime, but rather to produce a static self-contained application.

If it's possible, please provide a brief howto.

Thanks in advance.
January 30, 2017
In general case the library can depend on it being a dll, then it can't be linked statically.
January 30, 2017
On Monday, 30 January 2017 at 13:22:45 UTC, Kagamin wrote:
> In general case the library can depend on it being a dll, then it can't be linked statically.

OK, and in case I have a sqlite3.a file, what parameters should I pass to dmd to build a static application?
January 30, 2017
On Monday, 30 January 2017 at 13:29:20 UTC, Nestor wrote:
> OK, and in case I have a sqlite3.a file

Just pass the sqlite3.a file instead of sqlite3.lib and the compiler should do the rest... worst case is you might need to edit the source of my sqlite.d to comment out the pragma(lib) line to explicitly deny the dependency, but I think it will just work with the .a since it will find the functions in there.
January 30, 2017
On Monday, 30 January 2017 at 13:29:20 UTC, Nestor wrote:
> OK, and in case I have a sqlite3.a file, what parameters should I pass to dmd to build a static application?

If it's an import library, you will link against the dll dynamically (the library only contains bindings to dll). If it's a static library with sqlite code, you will link that code statically.
January 30, 2017
On Monday, 30 January 2017 at 13:58:45 UTC, Adam D. Ruppe wrote:
> On Monday, 30 January 2017 at 13:29:20 UTC, Nestor wrote:
>> OK, and in case I have a sqlite3.a file
>
> Just pass the sqlite3.a file instead of sqlite3.lib and the compiler should do the rest... worst case is you might need to edit the source of my sqlite.d to comment out the pragma(lib) line to explicitly deny the dependency, but I think it will just work with the .a since it will find the functions in there.

d:\prj\sqltest2\source>dmd app.d database.d sqlite.d sqlite3.a
Error: unrecognized file extension a

I took the file from http://math.seattleacademy.org/andersgibbons/fall17/node_modules/sqlite3/build/Release/ so I am not 100% sure it's compatible (I don't know how to build it myself), but in any case dmd doesn't recognize the extension.

If I delete the sqlite3.lib or remove the pragma from sqlite.d (or both), I get this instead:

d:\prj\sqltest2\source>dmd app.d database.d sqlite.d
OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_open
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_finalize
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_prepare_v2
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_free
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_mprintf
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_exec
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_last_insert_rowid
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_changes
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_errmsg
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_close
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_reset
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_blob
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_bytes
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_text
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_step
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_double
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_count
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_type
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_int
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_column_name
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_blob
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_null
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_double
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_int
app.obj(app)
 Error 42: Symbol Undefined _sqlite3_bind_text
Error: linker exited with status 214890840
January 30, 2017
That looks compiled for linux.
January 30, 2017
You'll probably be more successful with a static .lib library generated with the MS compiler (Visual Studio). I'd suggest compiling sqlite yourself and then using DMD with the `-m32mscoff` switch (32-bit) or `-m64` for 64-bit. Google is your friend in case you don't know how to build a static C library.

Oh apparently sqlite is a single C module, in that case it's even easier. Just compile the .c file with the MS compiler (cl.exe sqlite3.c) and specify the resulting sqlite3.obj file on the DMD command line (with `-m32mscoff` or `-m64`), so that it's linked in.
January 30, 2017
On Monday, 30 January 2017 at 13:00:15 UTC, Nestor wrote:
> Hi,
>
> In Windows, is it possible embed a dll library into an application (in this particular case, sqlite3.dll)? Notice I don't mean storing the resource in the application to extract it at runtime, but rather to produce a static self-contained application.
>
> If it's possible, please provide a brief howto.
>
> Thanks in advance.

As an alternative, you could build an object file from Sqlite's source code (e.g. the amalgamation file from Sqlite's website) with a C compiler. Then you just build your D application with:

dmd app.d sqlite3.d sqlite3.o[bj]

No dll. Sqlite statically linked.

You could also try https://code.dlang.org/packages/d2sqlite3 with option "--all-included". This wasn't tested much though.
January 30, 2017
On Monday, 30 January 2017 at 16:40:47 UTC, biozic wrote:
> You could also try https://code.dlang.org/packages/d2sqlite3 with option "--all-included". This wasn't tested much though.

Sorry, this uses a dll on Windows.

« First   ‹ Prev
1 2