Skip to content

Instantly share code, notes, and snippets.

@flymanzhao
Last active September 17, 2024 06:41
Show Gist options
  • Select an option

  • Save flymanzhao/e0ded3b0cacf47babab85a95a56dcae3 to your computer and use it in GitHub Desktop.

Select an option

Save flymanzhao/e0ded3b0cacf47babab85a95a56dcae3 to your computer and use it in GitHub Desktop.
编译到Native的语言HelloWorld二进制大小 Windows
## go
### code
```go
package main
func main() {
// 注意,这里没有使用 fmt.Println可以减少文件大小
print("Hello, World!\n")
}
```
### compile cmd
编译命令
```bash
go build -o hello_go.exe -ldflags="-s -w" hello.go
```
- "-s -w"的解释
- https://pkg.go.dev/cmd/link
- ```bash
go build -ldflags="-help" hello.go
```
### result
hello_go.exe 843 KB (863,744 字节)
## cpp/c++
### code
````c++
#include <cstdio>
int main()
{
printf("Hello World!");
}
````
### compile cmd
msvc
```bash
cl /c /Zi /W3 /WX- /diagnostics:column /sdl /O2 /Oi /GL /D NDEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /permissive- /Fo"x64\Release\\" /Fd"x64\Release\vc143.pdb" /external:W3 /Gd /TP /showIncludes /FC /errorReport:prompt hello.cpp
```
```bash
link.exe /ERRORREPORT:PROMPT /OUT:"x64\Release\hello.exe" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"x64\Release\hello.pdb" /SUBSYSTEM:CONSOLE /OPT:REF /OPT:ICF /LTCG:incremental /LTCGOUT:"x64\Release\hello.iobj" /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"x64\Release\hello.lib" /MACHINE:X64 x64\Release\hello.obj
```
### result
10.5 KB (10,752 字节)
## nim
### code
```nim
echo "Hello World!"
```
### compile cmd
```
nim c -d:release --opt:size --out=hello_nim_c.exe hello.nim
```
```
nim cpp -d:release --opt:size --out=hello_nim_cpp.exe hello.nim
```
### result
- hello_nim_c.exe
- 181 KB (185,955 字节)
- hello_nim_cpp.exe
- 136 KB (140,008 字节)
## Odin
### code
````go
package main
import "core:fmt"
main :: proc() {
fmt.println("Hello, World!")
}
````
### compile cmd
`odin build hello.odin -file -out:hello_odin.exe -o:size`
### result
242 KB (247,808 字节)
## Rust
### code
```rust
fn main() {
println!("Hello, world!");
}
```
### compile cmd
```
cargo build --release
```
### result
148 KB (152,064 字节)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment