为什么在某些项目中重新运行go build ./
每次会产生不同的结果?
例如:
$ cd go/src/github.com/google/cadvisor
$ go build ./
$ sh1sum cadvisor
cdfc3c38898e2decd5df35b661737f7cc4f514ed cadvisor
$ go build ./
$ sha1sum cadvisor
a94db96d684225e7a45cc68c5341fe6f57897c23 cadvisor
完全隔离的设置:
$ go version
go version go1.6.2 linux/amd64
$ export GOPATH=$(mktemp -d)
$ cd $GOPATH
$ go get github.com/tools/godep
$ go get github.com/google/cadvisor
package github.com/influxdb/influxdb/client: code in directory /tmp/tmp.2MxFdNmdDe/src/github.com/influxdb/influxdb/client expects import "github.com/influxdata/influxdb/client"
$ cd src/github.com/google/cadvisor
$ $GOPATH/bin/godep restore
godep: WARNING: Go version (go1.6) & $GO15VENDOREXPERIMENT= wants to enable the vendor experiment, but disabling because a Godep workspace (Godeps/_workspace) exists
$ go build ./
...
答案 0 :(得分:2)
答案 1 :(得分:0)
1-这是示例代码,每次构建时都会自行更改(也是因为嵌入式__DATE__
和__TIME__
会在每次构建时发生变化):
package main
/*
#include<stdint.h>
#include<string.h>
void getCompileDateTime(uint8_t dt[12],uint8_t tm[9]){
strcpy(dt, __DATE__); //Mmm dd yyyy
strcpy(tm, __TIME__); //hh:mm:ss
}
*/
import "C"
import (
"fmt"
"unsafe"
)
func main() {
dt := make([]byte, 12)
tm := make([]byte, 10)
C.getCompileDateTime((*C.uint8_t)(unsafe.Pointer(&dt[0])), (*C.uint8_t)(unsafe.Pointer(&tm[0])))
dts, tms := string(dt), string(tm)
fmt.Println(dts, tms)
}
2-
一旦使用了cgo,二进制文件将在DWARF中包含$ WORK路径 部分
目前的问题:
1. cgo版本中的$ WORK路径泄漏 2. $ WORK路径泄漏 - 测试和测试。
参考:https://github.com/golang/go/issues/9206
3- 将生成多次构建纯Go程序 相同的二进制文件
我希望这会有所帮助。