Static linking D apps for distribution to the cloud, etc.
David J Kordsmeier
dkords at gmail.com
Tue Oct 8 18:28:14 UTC 2019
Hi forums, I have what should be a simple question. I have an
application which I would like to distribute to the cloud onto a
linux system which I will not have root access. I thought it
should be easier for me to perform static linking of this D app
instead of packing the application with library dependencies.
If I try to do this, using my most simple example below, with
ldc2 (1.15.0) using the --static flag, I get various warnings:
warning: Using 'dlopen' in statically linked applications
requires at runtime the shared libraries from the glibc version
used for linking
warning: Using 'gethostbyaddr' in statically linked applications
requires at runtime the shared libraries from the glibc version
used for linking
If I use gdc (4.9.0 2.065) for this, I get linker errors, such
as: undefined reference to `curl_easy_setopt'
I'll go back and review the best practices for using curl with
phobos. I still am struggling to make this work, as something
that would be relatively simple in C to perform (statically link
to any libraries I would like). Without being an expert on
phobos library construction, what is the recommended practice for
app distribution? Does anyone have a great sample project to
point to? I've looked at the dlang-tour
https://github.com/dlang-tour/core/blob/master/dub.sdl , and this
indeed seems like the right track, however, I still get the curl
warnings and the app won't run.
I have also tried building and dynamically linking, which works
fine, but I've had trouble pulling the dependent libraries for
distribution, and namely having trouble with finding curl at
runtime.
```
import std.net.curl, std.stdio;
int main() {
auto http = HTTP("dlang.org");
http.onReceiveHeader = (in char[] key, in char[] value) {
writeln(key, ": ", value); };
http.onReceive = (ubyte[] data) { /+ drop +/ return
data.length; };
http.perform();
return 0;
}
```
More information about the Digitalmars-d
mailing list