doujiaoang69440 2012-12-11 23:40
浏览 151
已采纳

Golang-在SublimeText2中找不到包

when i try to execute my .go script with my package newmath i get following error in SublimeText2.

"test.go:5:2: import "newmath": cannot find package"

Thats my build-system in SublimeText2

{
"cmd": ["go","run", "${file}"],
"working_dir": "${file_path}",
"selector": "source.go, source.g"
}

but when i execute my script in the terminal the go-compiler can find the package and it is succesfully executed. And i have noticed that the GOPATH is reseted after reboot or after a while by itself :/

My Go env:

GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/daggi/gocode/"
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"

I think it is a path/environment problem of SublimeText2 but i dont know.

Thank you.

  • 写回答

2条回答 默认 最新

  • duanqin4238 2012-12-12 02:50
    关注

    It seems the build system does not share the GoSublime settings env, nor your own shell env. So you have to set it up specifically:

    Build systems

    {
        "cmd": ["go","run", "${file}"],
        "working_dir": "${file_path}",
        "selector": "source.go, source.g",
        "path": "/usr/lib/go/bin:$PATH",
        "env": {
            "GOPATH": "$HOME/gocode/",
            "GOROOT": "/usr/lib/go",
            "PATH": "/usr/lib/go/bin:$PATH"
        }
    }
    

    You could also switch your GOPATH setting to use ${project} instead of that explicit GOPATH, if you work in a way that your Sublime project is your GOPATH.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥30 python安卓开发
  • ¥15 使用R语言GD包一直不出结果