dongrang2140 2013-01-21 14:07
浏览 206
已采纳

Go编译器“没有这样的文件或目录”是什么意思?

I'm trying to compile a Go program made up of multiple modules, like so:

// main.go
package main
import "mst"
// do something interesting involving minimum spanning trees

// src/mst/kruskal.go
import "disjsets"
// Kruskal's algorithm follows

// src/disjsets/disjsets.go
// implements disjoint sets with union-find

Now, when I run either go run main.go or go build after export GOPATH=. in the directory containing both main.go and src, it prints

# disjsets
open src/disjsets/disjsets.go: No such file or directory

I don't get this. The file is there as ls -l src/disjsets/disjsets.go confirms. How can this happen? Where should the disjsets.go file live if Go is to find it?

(Google Go 1.0.2)

  • 写回答

2条回答 默认 最新

  • doomli3721 2013-01-21 14:25
    关注

    I believe you should read, or re-read How to Write Go code

    In short:

    Set you GOPATH to somewhere and export it for good. Then put some package blah into directory

    $GOPATH/src/foo/bar/baz/blah # (1)
    

    or

    $GOPATH/src/blah # (2)
    

    or

    $GOPATH/src/qux/blah # (3) etc.
    

    Import blah into other packages as

    import "foo/bar/baz/blah" // (1)
    

    or

    import "blah" // (2)
    

    or

    import "qux/blah" // (3)
    

    The package in that directory will contain the package files. Say you have only one, blah.go. Then its location would be

    $GOPATH/src/foo/bar/baz/blah/blah.go // (1)
    
    $GOPATH/src/blah/blah.go // (2)
    
    $GOPATH/src/qux/blah/blah.go // (3)
    

    If the blah package source file is named, say proj.go instead, then

    $GOPATH/src/foo/bar/baz/blah/proj.go // (1)
    
    $GOPATH/src/blah/proj.go // (2)
    
    $GOPATH/src/qux/blah/proj.go // (3)
    

    But the import paths would be the same as in the previous case.

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

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程