如何减少编译的文件大小? [英] How to reduce compiled file size?

查看:228
本文介绍了如何减少编译的文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比较c和go:
Hello_world.c:

  #include< stdio.h> 
int main(){
printf(Hello world!);
}

Hello_world.go:

  package main 
importfmt
func main(){
fmt.Printf(Hello world!)
}

同时编译:

  $ gcc Hello_world.c -o Hello_c 
$ 8g Hello_world.go -o Hello_go.8
$ 8l Hello_go.8 -o Hello_go



和...这是什么?

  $ ls -ls 
... 5,4K 2010-10-05 11:09 Hello_c
... 991K 2010-10-05 11:17 Hello_go

约1Mb Hello world。你在跟我开玩笑吗?
我做错了什么?



(strip hello_go - > 893K only)

解决方案

这是一个文件较大的问题吗?我不知道Go,但我会假设它静态链接一些运行时库,而C程序并非如此。但是,一旦你的程序变大,这可能就没什么好担心的了。

此处所述,静态链接Go运行时是默认的。该页面还会告诉您如何设置动态链接。


Lets compare c and go: Hello_world.c :

#include<stdio.h>
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_go

and ... what is it?

$ls -ls
... 5,4K 2010-10-05 11:09 Hello_c
... 991K 2010-10-05 11:17 Hello_go

About 1Mb Hello world. Are you kidding me? What I do wrong?

(strip Hello_go -> 893K only)

解决方案

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.

这篇关于如何减少编译的文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆