snippetgoModerate
How to reduce Go compiled file size?
Viewed 0 times
reducehowcompiledfilesize
Problem
Lets compare c and go:
Hello_world.c :
Hello_world.go:
Compile both:
and ... what is it?
About 1Mb Hello world. Are you kidding me?
What I do wrong?
(strip Hello_go -> 893K only)
Hello_world.c :
#include
int main(){
printf("Hello world!");
}Hello_world.go:
package main
import "fmt"
func main(){
fmt.Printf("Hello world!")
}Compile both:
$gcc Hello_world.c -o Hello_c
$8g Hello_world.go -o Hello_go.8
$8l Hello_go.8 -o Hello_goand ... what is it?
$ls -ls
... 5,4K 2010-10-05 11:09 Hello_c
... 991K 2010-10-05 11:17 Hello_goAbout 1Mb Hello world. Are you kidding me?
What I do wrong?
(strip Hello_go -> 893K only)
Solution
Note: This answer is outdated
Please note that this answer is outdated. Please refer to the other higher-voted answers. I would like to delete this post, accepted answers can't be deleted though.
Is it a problem that the file is larger? I don't know Go but I would assume that it statically links some runtime lib which is not the case for the C program. But probably that is nothing to worry about as soon as your program gets larger.
As described here, statically linking the Go runtime is the default. That page also tells you how to set up for dynamic linking.
Please note that this answer is outdated. Please refer to the other higher-voted answers. I would like to delete this post, accepted answers can't be deleted though.
Is it a problem that the file is larger? I don't know Go but I would assume that it statically links some runtime lib which is not the case for the C program. But probably that is nothing to worry about as soon as your program gets larger.
As described here, statically linking the Go runtime is the default. That page also tells you how to set up for dynamic linking.
Context
Stack Overflow Q#3861634, score: 34
Revisions (0)
No revisions yet.