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 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起