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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵