5 ms·
Static linking is not easily available with C/C++ in the general case. Some libraries support it, some important ones like Glibc and GTK+ do not.
by jkn 14y ago
Static linking is not easily available with C/C++ in the general case. Some libraries support it, some important ones like Glibc and GTK+ do not.
- pjmlp 14y agoThe only reason this is not an issue with Go is that the language is too young and the reference compiler only supports static linking fot the time being. The moment the compiler starts supporting dynamic linking the same will happen to Go.
- 4ad 14y agoStatic linking of Go code is a conscious design decision, not some artifact of toolchain immaturity. It will never change.
- reddit_clone 14y agoOn a related note, using Go can one develop DLLs that can be dynamically consumed from other applications? Or you can only produce statically linked exe's?
- zimbatm 14y agoOnly exes at the time being. Go is the main loop and needs to have control of the execution flow for concurrency. If you think of it, DLLs are a bit like separate programs that you communicate with trough the C call stack instead of another structured protocol. In Go you would spawn different processes and use something like protobuf to exchange messages.
- pjmlp 14y agoYou can make use of dynamic linking with gccgo, as far as I am aware.
- koenigdavidmj 14y agoThe Plan 9 people (basically the same group as the Go people) have some philosophical problems with dynamic linking. Read http://harmful.cat-v.org/software/dynamic-linking/ http://harmful.cat-v.org/software/dynamic-linking/ for their arguments.
- johnm 14y agoMakes the choice of using them that much easier. :-)
- 1amzave 14y agoHuh? Perhaps you mean Glib? Static linking works just fine with glibc: [me@host: tmp]% cat > hello.c #include <stdio.h> int main(void) { printf("hello world\n"); return 0; } [me@host: tmp]% gcc -o hello -Wall hello.c -static [me@host: tmp]% file hello hello: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, not stripped [me@host: tmp]% ldd hello not a dynamic executable [me@host: tmp]% ./hello hello world
- saurik 14y agoI largely agree with you, but for what it's worth, that doesn't "just work": there are places in glibc that use dlopen to pull in modular code; one example is the DNS resolver.
- tedunangst 14y agoAs mentioned, if you try that it works less than 100%. Trying to run a 32-bit program on a 64-bit host will fail in weird ways unless some of the expected bonus libraries are available.
- gillianseed 14y agoAlthough I've never tried it myself I've read that gtk supports static linking, iirc you have to build gtk with --disable-modules. Also, Go has gtk bindings, how does that work?
- tedunangst 14y agoGo can dynanmically load C libraries I believe, but there is no support for native shared go code.
- 4ad 14y agoThat is correct.
- jkn 14y agoAh you're right, it seems you can get a static build by recompiling GTK+ and its dependencies with the appropriate flags and some extra manipulation... See http://wiki.inkscape.org/wiki/index.php/CompilingStatic http://wiki.inkscape.org/wiki/index.php/CompilingStatic for an outdated example. I don't know if that would work on Windows, it used to be not supported: http://readlist.com/lists/lists.sourceforge.net/mingw-users/1/5388.html http://readlist.com/lists/lists.sourceforge.net/mingw-users/...