2017-04-24 66 views
-1

我想用go語言來調試標準庫,所以我給標準庫文件添加了一些日誌,但是這並沒有什麼區別,我想我應該重建.a文件,我該怎麼做?如何在golang中構建stdlib文件?

$ go version 
go version go1.8.1 darwin/amd64 

$ go env 
GOARCH="amd64" 
GOBIN="/usr/local/go1.8.1/bin" 
GOEXE="" 
GOHOSTARCH="amd64" 
GOHOSTOS="darwin" 
GOOS="darwin" 
GOPATH="/Users/bitstore/Projects/go" 
GORACE="" 
GOROOT="/usr/local/go1.8.1" 
GOTOOLDIR="/usr/local/go1.8.1/pkg/tool/darwin_amd64" 
GCCGO="gccgo" 
CC="clang" 
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4r/62myx2852db5cdvrtqx63gl40000gn/T/go-build009034286=/tmp/go-build -gno-record-gcc-switches -fno-common" 
CXX="clang++" 
CGO_ENABLED="1" 
PKG_CONFIG="pkg-config" 
CGO_CFLAGS="-g -O2" 
CGO_CPPFLAGS="" 
CGO_CXXFLAGS="-g -O2" 
CGO_FFLAGS="-g -O2" 
CGO_LDFLAGS="-g -O2" 

$ go install -v text/scanner 
output nothing 

I install use environment variables 
export GOROOT=/usr/local/go1.8.1 
export GOBIN=$GOROOT/bin 
export GOPATH=$HOME/Projects/go 
export PATH=$PATH:$GOBIN:$GOPATH/bin 

$ ls -la /usr/local/go1.8.1/src/text/scanner/scanner.go 
-rw-r--r-- 1 bitstore staff 17545 4 24 22:19 /usr/local/go1.8.1/src/text/scanner/scanner.go 
$ go install -v text/scanner 
$ ls -la /usr/local/go1.8.1/pkg/darwin_amd64/text/scanner.a 
[email protected] 1 bitstore staff 53838 4 8 00:54 /usr/local/go1.8.1/pkg/darwin_amd64/text/scanner.a 
+2

你運行了'go install packagename'嗎?你想要構建什麼包? – JimB

+0

@JimB文本/掃描儀,它不是gopath,它是goroot中的標準庫 – bitstore

+0

好吧,但是你有沒有試過'去安裝文本/掃描儀?這就是你如何安裝任何軟件包。 (或者你可以從源代碼安裝Go,並使用相同的程序) – JimB

回答

1

Go工具查看源時間戳以查看是否需要安裝。例如,

$ cd ~ 
$ touch /home/peter/go/src/text/scanner/scanner.go 
$ go install -v text/scanner/ 
text/scanner 
$ go install -v text/scanner/ 
$ 

go install看起來$GOROOT然後$GOPATH

go versiongo env命令的輸出是什麼?

$ go version 
go version devel +1737aef Mon Apr 24 12:37:49 2017 +0000 linux/amd64 

$ go env 
GOARCH="amd64" 
GOBIN="" 
GOEXE="" 
GOHOSTARCH="amd64" 
GOHOSTOS="linux" 
GOOS="linux" 
GOPATH="/home/peter/gopath" 
GORACE="" 
GOROOT="/home/peter/go" 
GOTOOLDIR="/home/peter/go/pkg/tool/linux_amd64" 
GCCGO="gccgo" 
CC="gcc" 
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build148116572=/tmp/go-build -gno-record-gcc-switches" 
CXX="g++" 
CGO_ENABLED="1" 
CGO_CFLAGS="-g -O2" 
CGO_CPPFLAGS="" 
CGO_CXXFLAGS="-g -O2" 
CGO_FFLAGS="-g -O2" 
CGO_LDFLAGS="-g -O2" 
PKG_CONFIG="pkg-config" 
$ 

你是怎麼安裝Go的?

+0

3ks回答,我更新了問題的詳細信息 – bitstore

+0

在'go install -v text/scanner'之前,您沒有'touch/usr/local/go1.8.1/src/text/scanner/scanner.go'。 – peterSO

+0

我已經觸摸它,但.a文件仍然不會改變,因爲我更新了 – bitstore