6g将complete标志视为输出标志,导致出现”pack: cannot open”错误。

huangapple go评论86阅读模式
英文:

6g treating complete flag as output flag resulting in "pack: cannot open" error

问题

我开始在所有我的Go项目中遇到一个pack: cannot open错误。

尝试运行一个简单的Go文件:

main.go:

package main

import "fmt"

func main() {
	fmt.Println("Hello, playground")
}

得到了相同的结果:

$ go run main.go
# command-line-arguments
pack: cannot open $WORK/command-line-arguments/_obj/_go_.6

我在目录中有一个名为mplete的新文件,似乎是6g编译器的输出。

手动运行go run -x main.go输出的步骤,我发现6g编译器将标志-complete解析为-o mplete。这将输出文件设置为meplete

$ ls
main.go  work_tmp
$ /usr/local/go/pkg/tool/linux_amd64/6g -o $WORK/command-line-arguments/_obj/_go_.6 -p command-line-arguments -complete -D _/tmp/taco -I $WORK ./main.go
$ ls
main.go  mplete  work_tmp

更改-complete标志会更改输出的文件:

$ ls
main.go  work_tmp
$ /usr/local/go/pkg/tool/linux_amd64/6g -o $WORK/command-line-arguments/_obj/_go_.6 -p command-line-arguments -cotaco -D _/tmp/taco -I $WORK ./main.go
$ ls
main.go  taco  work_tmp

我的go env

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jpoz/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"
英文:

Started getting a pack: cannot open error on all my go projects.

Tried to run a simple go file:

main.go:
<pre><code>package main

import "fmt"

func main() {
fmt.Println("Hello, playground")
}
</code></pre>

and got the same result:

<pre><code>$ go run main.go

command-line-arguments

pack: cannot open $WORK/command-line-arguments/_obj/go.6
</code></pre>

I did have a new file in the directory called mplete which seemed to be the output from the 6g compiler.

running the steps output from go run -x main.go manually I found the 6g compiler is taking the flag -complete and reading it as -o mplete. Which sets the output file to meplete

<pre><code>$ ls
main.go work_tmp
$ /usr/local/go/pkg/tool/linux_amd64/6g -o $WORK/command-line-arguments/_obj/go.6 -p command-line-arguments -complete -D _/tmp/taco -I $WORK ./main.go
$ ls
main.go mplete work_tmp
</code></pre>

Changing the -complete flag changed the file that was output:

<pre><code>$ ls
main.go work_tmp
$ /usr/local/go/pkg/tool/linux_amd64/6g -o $WORK/command-line-arguments/_obj/go.6 -p command-line-arguments -cotaco -D _/tmp/taco -I $WORK ./main.go
$ ls
main.go taco work_tmp
</code></pre>

My go evn

<pre><code>GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jpoz/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"
</code></pre>

答案1

得分: 1

搞定了!

我在我的机器上安装了两个版本的Go:

/usr/local/go 中的 go1.0.3

/usr/local/bin/go 中的 go1.1.1

which go 命令会使用 go1.1.1,但由于 GOROOT 设置为 /usr/local/go,所以构建过程使用的是旧的 6g 编译器!

英文:

Figured it out!

I had two version of go installed on my machine:

go1.0.3 in /usr/local/go
and
go1.1.1 in /usr/local/bin/go

which go would use go1.1.1 but since GOROOT was set to /usr/local/go the build was using the old 6g compiler!!

huangapple
  • 本文由 发表于 2013年10月31日 05:08:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/19693832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定