digitalmars.D.learn - How to deploy single exe application (?)
- Willem (10/10) Nov 15 2021 Using D -- I have created a simple command line utility that
- pilger (2/4) Nov 15 2021 https://p0nce.github.io/d-idioms/#Embed-a-dynamic-library-in-an-executab...
- Willem (22/26) Nov 28 2021 Many Thanks all for the responses.
- Imperatorn (2/11) Nov 28 2021 Did you try the import solution?
- Willem (45/46) Nov 28 2021 I think so ... below is my test program.
- Imperatorn (2/8) Nov 28 2021 https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library...
- Mike Parker (10/22) Nov 28 2021 `DerelictSDL2.load()` cannot load curl. It is not a generic dll
- Willem (18/27) Nov 29 2021 Thanks again for all the responses. For now -- I am simply adding
- forkit (4/7) Nov 29 2021 "Programmers are not to be measured by their ingenuity and their
- bauss (4/7) Nov 30 2021 If you intend to distribute it then becareful with this as it
- Guillaume Piolat (3/12) Dec 01 2021 Huh, I never intended for someone to actually use this :|
- Guillaume Piolat (3/5) Dec 01 2021 You can create an installer rather easily with InnoSetup instead.
- kinke (5/7) Nov 28 2021 LDC ships with a static curl library - `lib\curl_a.lib`. IIRC,
- kinke (2/3) Nov 28 2021 Typo, should have been `lib\curl.exp`.
- russhy (12/22) Nov 15 2021 you can statically link libraries just like in other languages
- Imperatorn (4/29) Nov 15 2021 You are correct. But that only works if you got the static libs.
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
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
On Monday, 15 November 2021 at 21:53:04 UTC, pilger wrote:On Monday, 15 November 2021 at 21:16:14 UTC, Willem 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 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 ThanksAny feedback / pointers on where to start would be greatly appreciated.https://p0nce.github.io/d-idioms/#Embed-a-dynamic-library-in-an-executable
Nov 28 2021
On Sunday, 28 November 2021 at 16:08:20 UTC, Willem wrote:On Monday, 15 November 2021 at 21:53:04 UTC, pilger wrote:Did you try the import solution?[...]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 [...]
Nov 28 2021
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
On Sunday, 28 November 2021 at 22:45:29 UTC, Willem wrote:On Sunday, 28 November 2021 at 16:12:42 UTC, Imperatorn wrote:https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order[...]I think so ... below is my test program. It executes OK - but it is not using the imported libcurl dll. Many Thanks. [...]
Nov 28 2021
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
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
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
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
On Wednesday, 1 December 2021 at 07:45:21 UTC, bauss wrote:On Monday, 29 November 2021 at 14:58:07 UTC, Willem wrote:Huh, I never intended for someone to actually use this :| Such a thing will never work on macOS for example.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.
Dec 01 2021
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
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
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
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, Willemyou 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
On Monday, 15 November 2021 at 22:28:41 UTC, russhy wrote:On Monday, 15 November 2021 at 21:16:14 UTC, Willem wrote: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).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, Willemyou 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