2015-07-11 94 views

回答

2

正如在「Linking golang statically」(Vincent Batts)提到:

只要被編譯的來源是原生走了,走編譯器將靜態鏈接的可執行文件。
雖然當您需要使用cgo時,編譯器必須使用其外部鏈接器。

一個純粹的圍棋程序會顯示這樣的:

$> go build ./code-pure.go 
$> ldd ./code-pure 
     not a dynamic executable 
$> file ./code-pure 
./code-pure: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped 

其實並非如此與CGO,除非你添加一個額外的標誌,如:

go build --ldflags '-extldflags "-static"' ./code-cgo.go 
# or, with gccgo 
go build -compiler gccgo --gccgoflags "-static" ./code-cgo.go 

提醒,即使進入1.5(用於編譯,而不是gc),gccgo will still be there

相關問題