12 ms·
With other languages such as C/C++ if you link a library into your program statically, that library may dynamically load other dependencies. In Go, all dependen
by genbattle 14y ago
With other languages such as C/C++ if you link a library into your program statically, that library may dynamically load other dependencies. In Go, all dependencies have to be statically compiled into that package.
Rob Pike made a good point about this in one of the Go talks [1] (I think it was the "Meet the Go team" talk) when they were talking about package management and the static linking, and how in C++ you could get massive chains of useless includes (I think is came out of a question on the speed of the Go compiler). His reasoning was that all the code you need to compile a package should be in the one package binary. You shouldn't need to worry about having other 3rd-party packages that your dependency depends on installed on the target system.
[1] http://blog.golang.org/2012/07/go-videos-from-google-io-2012.html http://blog.golang.org/2012/07/go-videos-from-google-io-2012...
- pjmlp 14y ago> In Go, all dependencies have to be statically compiled into that package. This is not true. If you make use of cgo, the dependencies are linked dynamically.
- 4ad 14y agoUsing cgo is an exception rather than the rule, and when Rob talks about package dependencies he means any file required for building that package, not only the shared objects. This includes C/C++ header files. Even with cgo, to use a package that uses cgo you only need that package archive, you need not care about what files that created that package.
- pjmlp 14y agoLike in every other compiled language that has modules.
- genbattle 14y agoYes, you are right. I was referring to pure Go packages.