英文:
How to build stdlib a file in golang?
问题
我想要在Go语言中调试标准库,所以我在一个标准库文件中添加了一些日志,但是这没有任何效果,我认为我应该重新构建.a文件,我该如何做呢?
$ 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
没有输出
我使用环境变量进行安装
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
-rw-r--r--@ 1 bitstore staff 53838 4 8 00:54 /usr/local/go1.8.1/pkg/darwin_amd64/text/scanner.a
英文:
I want to debug standard library in go language, so I add some log to a standard library file, but this does not make any difference, I think I should rebuild the .a file, how can I do this?
$ 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
-rw-r--r--@ 1 bitstore staff 53838 4 8 00:54 /usr/local/go1.8.1/pkg/darwin_amd64/text/scanner.a
答案1
得分: 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 version
和 go 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的?
英文:
The Go tools look at the source timestamps to see if installation is necessary. For example,
$ cd ~
$ touch /home/peter/go/src/text/scanner/scanner.go
$ go install -v text/scanner/
text/scanner
$ go install -v text/scanner/
$
go install
looks in $GOROOT
then $GOPATH
.
What is your output from the go version
and go env
commands?
$ 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"
$
How did you install Go?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论