英文:
Can't compile program that imports net/http on OS X with homebrew install
问题
我已经在我的OS X 10.10机器上使用Homebrew安装了Go。每次我尝试编译一个导入net/http的示例应用程序时,都会出现以下错误:
load cmd/cgo: package cmd/cgo: no Go source files in /Users/bbaron/google_appengine/goroot/src/cmd/cgo
我已经正确设置了我的GOPATH变量($HOME/go),并且我的目录结构似乎也是正确的:
/Users/bbaron/go/src/github.com/einsteinx2/gamenotifier
/Users/bbaron/go/src/github.com/einsteinx2/gamenotifier/server.go
为什么cgo似乎认为GOPATH是$HOME/google_appengine/goroot?
我之前(大约一年前)使用App Engine进行过一些Go开发,所以肯定有一些残留的垃圾,但我无法弄清楚我需要更改什么才能使其正常工作。
我已经将App Engine SDK安装到$HOME/google_appengine,但我不明白为什么在我没有导入任何App Engine的内容时会影响到任何东西。
有什么想法吗?
编辑:看起来问题出在我的GOROOT上。以下也是go env的输出:
GOROOT="/Users/bbaron/google_appengine/goroot"
GOTOOLDIR="/Users/bbaron/google_appengine/goroot/pkg/tool/darwin_amd64"
但是,即使我导出了正确的GOROOT并使用echo $GOROOT进行检查,go env仍然没有看到正确的GOROOT。
英文:
I've installed go using Homebrew on my OS X 10.10 machine. Every time I try to compile a sample app that imports net/http, I get the following error:
load cmd/cgo: package cmd/cgo: no Go source files in /Users/bbaron/google_appengine/goroot/src/cmd/cgo
I have my GOPATH variable set correctly ($HOME/go) and my directory structure appears to be correct:
/Users/bbaron/go/src/github.com/einsteinx2/gamenotifier
/Users/bbaron/go/src/github.com/einsteinx2/gamenotifier/server.go
Why does cgo seem to thing the GOPATH is $HOME/google_appengine/goroot
I previously (maybe a year ago) did some go development using App Engine, so there must be some left over garbage, but I can't figure out what I need to change to get this working.
I do have the App Engine SDK installed to $HOME/google_appengine but I don't see why that's affecting anything when I'm not importing any App Engine stuff.
Any ideas?
EDIT: It looks like the problem is my GOROOT. The following are also in go env:
GOROOT="/Users/bbaron/google_appengine/goroot"
GOTOOLDIR="/Users/bbaron/google_appengine/goroot/pkg/tool/darwin_amd64"
But even if I export a correct GOROOT and check with echo $GOROOT, go env does not see the correct GOROOT
答案1
得分: 0
原来是我的Google App Engine安装在某种程度上破坏了这些环境变量。我删除了我的主目录中的google_appengine文件夹,然后卸载了Homebrew版本的Go,并从官方的OS X软件包重新安装,现在一切都正常工作了。
英文:
It turned out that my google app engine installation was clobbering these environment variables somehow. I deleted the folder google_appengine in my home directory and then uninstalled the Homebrew version of Go and reinstalled from the official OS X package and now it's working fine.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论