www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - embedding a library in Windows

reply Nestor <nestorperez2016 yopmail.com> writes:
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.
Jan 30
next sibling parent reply Kagamin <spam here.lot> writes:
In general case the library can depend on it being a dll, then it 
can't be linked statically.
Jan 30
parent reply Nestor <nestorperez2016 yopmail.com> writes:
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?
Jan 30
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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.
Jan 30
parent reply Nestor <nestorperez2016 yopmail.com> writes:
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/sq ite3/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
Jan 30
next sibling parent Kagamin <spam here.lot> writes:
That looks compiled for linux.
Jan 30
prev sibling parent kinke <noone nowhere.com> writes:
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.
Jan 30
prev sibling parent Kagamin <spam here.lot> writes:
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.
Jan 30
prev sibling parent reply biozic <dransic gmail.com> writes:
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.
Jan 30
next sibling parent biozic <dransic gmail.com> writes:
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.
Jan 30
prev sibling parent reply Nestor <nestorperez2016 yopmail.com> writes:
On Monday, 30 January 2017 at 16:40:47 UTC, biozic wrote:
 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.
I tried to compile a static library with MinGW (which is the one I have at hand, v4.8.1) with this command: gcc -static -c sqlite3.c However: D:\prj\sqltest2\source>dmd app.d database.d sqlite.d sqlite3.o Error: unrecognized file extension o
Jan 30
parent biozic <dransic gmail.com> writes:
On Monday, 30 January 2017 at 17:25:13 UTC, Nestor wrote:
 On Monday, 30 January 2017 at 16:40:47 UTC, biozic wrote:
 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.
I tried to compile a static library with MinGW (which is the one I have at hand, v4.8.1) with this command: gcc -static -c sqlite3.c However: D:\prj\sqltest2\source>dmd app.d database.d sqlite.d sqlite3.o Error: unrecognized file extension o
Sorry, I never used Mingw32. It's either an incompatible object file format, or dmd only accepts .obj extensions, or both... You could also use the dmc compiler (http://ftp.digitalmars.com/dmc.zip). Or see kinke's answer about using the MS compiler.
Jan 30