www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to deploy single exe application (?)

reply Willem <willem m.com> writes:
Using D -- I have created a simple command line utility that 
download some info via a https API and save it in a sqlite3 
database file. To use the exe on another windows machine, I need 
to copy over the relevant sqlite3 and curl DLL files.

Question:  Is there a way to create a single .exe with the 
relevant windows DLL info in there? Can this be done with static 
linking?

Any feedback / pointers on where to start would be greatly 
appreciated.

Many Thanks, Willem
Nov 15 2021
next sibling parent reply pilger <abcd dcba.com> writes:
On Monday, 15 November 2021 at 21:16:14 UTC, Willem wrote:
 Any feedback / pointers on where to start would be greatly 
 appreciated.
https://p0nce.github.io/d-idioms/#Embed-a-dynamic-library-in-an-executable
Nov 15 2021
parent reply Willem <willem m.com> writes:
On Monday, 15 November 2021 at 21:53:04 UTC, pilger wrote:
 On Monday, 15 November 2021 at 21:16:14 UTC, Willem wrote:
 Any feedback / pointers on where to start would be greatly 
 appreciated.
https://p0nce.github.io/d-idioms/#Embed-a-dynamic-library-in-an-executable
Many Thanks all for the responses. Reminder of my requirements: - I am using d2sqlite3 and std.net.curl in a Windows 64 D program - Want to create a single exe file that I can distribute to other people without the need to distribute the related DLL's Progress to date: sqlite3: - I found a static compiled version of sqlite3.lib. So I am now able to link sqlite3 into my exe. curl: - No luck with curl yet. - As per comment from pilger -- I got the sample DerelictSDL2 program working after adding "derelict-sdl2": "~>3.0.0-beta" to dub.json and "import derelict.sdl2.sdl;" to app.d - I see the exe is bigger, so I assume it it added to the relevant curl DLL -- but the separate Windows DLL file is still required to execute the exe. So it is not finding the imported DLL file! Is it possible to distribute an .exe file without the required libcurl DLL? Many Thanks
Nov 28 2021
next sibling parent reply Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Sunday, 28 November 2021 at 16:08:20 UTC, Willem wrote:
 On Monday, 15 November 2021 at 21:53:04 UTC, pilger wrote:
 [...]
Many Thanks all for the responses. Reminder of my requirements: - I am using d2sqlite3 and std.net.curl in a Windows 64 D program - Want to create a single exe file that I can distribute to other people without the need to distribute the related DLL's [...]
Did you try the import solution?
Nov 28 2021
parent reply Willem <willem matimba.com> writes:
On Sunday, 28 November 2021 at 16:12:42 UTC, Imperatorn wrote:

 Did you try the import solution?
I think so ... below is my test program. It executes OK - but it is not using the imported libcurl dll. Many Thanks. ========== app.d ============ ``` import std.stdio; import std.uuid; import std.file; import std.path; import std.string; import derelict.sdl2.sdl; ubyte[] sdlBytes = cast(ubyte[]) import("SDL2.dll"); ubyte[] curlBytes = cast(ubyte[]) import("libcurl.dll"); void main(string[] args) { // load sdl string uuid = randomUUID().toString(); string filename = format("SDL2-%s.dll", uuid); string depacked = buildPath(tempDir(), filename); std.file.write(depacked, sdlBytes); DerelictSDL2.load(depacked); // load curl string uuid2 = randomUUID().toString(); string filename2 = format("libcurl-%s.dll", uuid2); string depacked2 = buildPath(tempDir(), filename2); std.file.write(depacked2, curlBytes); DerelictSDL2.load(depacked2); // test curl import std.net.curl; auto content = get("https://httpbin.org/get"); writeln(content); writeln("..DONE"); } ``` ========== dub.json ============ ``` { "dependencies": { "derelict-sdl2": "~>2.1.4" }, "name": "add-sdl", "stringImportPaths": ["./dll"] } ```
Nov 28 2021
next sibling parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Sunday, 28 November 2021 at 22:45:29 UTC, Willem wrote:
 On Sunday, 28 November 2021 at 16:12:42 UTC, Imperatorn wrote:

 [...]
I think so ... below is my test program. It executes OK - but it is not using the imported libcurl dll. Many Thanks. [...]
https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order
Nov 28 2021
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On Sunday, 28 November 2021 at 22:45:29 UTC, Willem wrote:

     // load sdl
     string uuid = randomUUID().toString();
     string filename = format("SDL2-%s.dll", uuid);
     string depacked = buildPath(tempDir(), filename);
     std.file.write(depacked, sdlBytes);
     DerelictSDL2.load(depacked);

     // load curl
     string uuid2 = randomUUID().toString();
     string filename2 = format("libcurl-%s.dll", uuid2);
     string depacked2 = buildPath(tempDir(), filename2);
     std.file.write(depacked2, curlBytes);
     DerelictSDL2.load(depacked2);
`DerelictSDL2.load()` cannot load curl. It is not a generic dll loader. It only loads SDL and doesn't know anything about curl or any other library. In order to dynamically load curl like this, you need a binding that supports it, i.e., a binding that declares the curl API as function pointers and knows how to load them from the DLL. Also, DerelictSDL2 is no longer maintained. Please use bindbc-sdl for new projects: http://bindbc-sdl.dub.pm/
Nov 28 2021
parent reply Willem <willem m.com> writes:
On Monday, 29 November 2021 at 07:29:35 UTC, Mike Parker wrote:
 `DerelictSDL2.load()` cannot load curl. It is not a generic dll 
 loader. It only loads SDL and doesn't know anything about curl 
 or any other library.

 In order to dynamically load curl like this, you need a binding 
 that supports it, i.e., a binding that declares the curl API as 
 function pointers and knows how to load them from the DLL.

 Also, DerelictSDL2 is no longer maintained. Please use 
 bindbc-sdl for new projects:

 http://bindbc-sdl.dub.pm/
Thanks again for all the responses. For now -- I am simply adding the DLL to the EXE and writing it out to the working directory. Not elegant - but it does work. ``` import std.stdio; import std.file; ubyte[] curlBytes = cast(ubyte[]) import("libcurl.dll"); void main(string[] args) { std.file.write("libcurl.dll", curlBytes); // test curl import std.net.curl; auto content = get("https://httpbin.org/get"); writeln(content); writeln("..DONE"); } ```
Nov 29 2021
next sibling parent forkit <forkit gmail.com> writes:
On Monday, 29 November 2021 at 14:58:07 UTC, Willem wrote:
 Thanks again for all the responses. For now -- I am simply 
 adding the DLL to the EXE and writing it out to the working 
 directory.   Not elegant - but it does work.
"Programmers are not to be measured by their ingenuity and their logic but by the completeness of their case analysis." - Alan Perlis.
Nov 29 2021
prev sibling parent reply bauss <jj_1337 live.dk> writes:
On Monday, 29 November 2021 at 14:58:07 UTC, Willem wrote:
 Thanks again for all the responses. For now -- I am simply 
 adding the DLL to the EXE and writing it out to the working 
 directory.   Not elegant - but it does work.
If you intend to distribute it then becareful with this as it might trigger some (if not all) antiviruses under most configurations.
Nov 30 2021
parent reply Guillaume Piolat <first.last gmail.com> writes:
On Wednesday, 1 December 2021 at 07:45:21 UTC, bauss wrote:
 On Monday, 29 November 2021 at 14:58:07 UTC, Willem wrote:
 Thanks again for all the responses. For now -- I am simply 
 adding the DLL to the EXE and writing it out to the working 
 directory.   Not elegant - but it does work.
If you intend to distribute it then becareful with this as it might trigger some (if not all) antiviruses under most configurations.
Huh, I never intended for someone to actually use this :| Such a thing will never work on macOS for example.
Dec 01 2021
parent Guillaume Piolat <first.last gmail.com> writes:
On Wednesday, 1 December 2021 at 09:49:56 UTC, Guillaume Piolat 
wrote:
 Huh, I never intended for someone to actually use this :|
 Such a thing will never work on macOS for example.
You can create an installer rather easily with InnoSetup instead.
Dec 01 2021
prev sibling parent reply kinke <noone nowhere.com> writes:
On Sunday, 28 November 2021 at 16:08:20 UTC, Willem wrote:
 Is it possible to distribute an .exe file without the required 
 libcurl DLL?
LDC ships with a static curl library - `lib\curl_a.lib`. IIRC, you'll also need to export the curl symbols from the .exe for std.net.curl consumption, by adding `ldc\curl.exp` in the compiler command-line too.
Nov 28 2021
parent kinke <noone nowhere.com> writes:
On Monday, 29 November 2021 at 03:59:11 UTC, kinke wrote:
 `ldc\curl.exp`
Typo, should have been `lib\curl.exp`.
Nov 28 2021
prev sibling parent reply russhy <russhy gmail.com> writes:
On Monday, 15 November 2021 at 21:16:14 UTC, Willem wrote:
 Using D -- I have created a simple command line utility that 
 download some info via a https API and save it in a sqlite3 
 database file. To use the exe on another windows machine, I 
 need to copy over the relevant sqlite3 and curl DLL files.

 Question:  Is there a way to create a single .exe with the 
 relevant windows DLL info in there? Can this be done with 
 static linking?

 Any feedback / pointers on where to start would be greatly 
 appreciated.

 Many Thanks, Willem
you can statically link libraries just like in other languages if you use dub it's as easy as this: ```json "sourceFiles-windows": [ "../_clibs/glfw3.lib", ] ``` if you use plain dmd, then it's simple ``` dmd main.d mylib.lib ```
Nov 15 2021
parent Imperatorn <johan_forsberg_86 hotmail.com> writes:
On Monday, 15 November 2021 at 22:28:41 UTC, russhy wrote:
 On Monday, 15 November 2021 at 21:16:14 UTC, Willem wrote:
 Using D -- I have created a simple command line utility that 
 download some info via a https API and save it in a sqlite3 
 database file. To use the exe on another windows machine, I 
 need to copy over the relevant sqlite3 and curl DLL files.

 Question:  Is there a way to create a single .exe with the 
 relevant windows DLL info in there? Can this be done with 
 static linking?

 Any feedback / pointers on where to start would be greatly 
 appreciated.

 Many Thanks, Willem
you can statically link libraries just like in other languages if you use dub it's as easy as this: ```json "sourceFiles-windows": [ "../_clibs/glfw3.lib", ] ``` if you use plain dmd, then it's simple ``` dmd main.d mylib.lib ```
You are correct. But that only works if you got the static libs. If you only have the dynamic libs you have to resort to embedding them (if you don't want to ship them separately).
Nov 15 2021