zoukankan      html  css  js  c++  java
  • go build报错cannot find package

    go env 关键数据是这样的
    GOPATH="/home/zzy/goProject"
    GOROOT="/usr/local/go"

    项目目录是这样的

    goProject
    ├── bin
    ├── pkg
    └── src
        └── go_learn
                └── day01
                    ├── hello
                    │   ├── hello
                    │   └── hello.go
                    └── str_type
                        ├── str.go
                        └── world.go
    hello.go我的代码是这样的
    package main
    
    import (
        "fmt"
        "go_learn/day01/str_type/world"    ## 这句导入包,一直报错
    )
    func main()  {
        fmt.Print("hello world")
        test()
    }
    world.go代码是这样的
    package main
    
    import "fmt"
    
    func test()  {
        fmt.Print("啦啦啦啦")
    
    }
    go build 报错是这样的
    $ go build
    hello.go:5:2: cannot find package "go_learn/day01/str_type/world" in any of:
            /usr/local/go/src/go_learn/day01/str_type/world (from $GOROOT)
            /home/zzy/goProject/src/go_learn/day01/str_type/world (from $GOPATH)

    最后解决了!十分low的一个问题,估计初学者才会犯

    world.go文件内容改一下就可以

    package  world  # 是个文件,不是包,不要导入main
    
    import "fmt"
    
    # 函数名大写,就可以在外面引用该函数
    func Test()  {
        fmt.Println("lll")
        
    }
  • 相关阅读:
    Java 编程基础
    LING 实战
    C# 3.0\3.5 新特性
    EF Code First 入门
    C# 4.0 新特性
    JavaScript学习(二)
    JavaScript学习(一)
    csdn的blog后台程序的导航菜单的实现
    HashTable的遍历
    开通啦
  • 原文地址:https://www.cnblogs.com/zzy-9318/p/10408488.html
Copyright © 2011-2022 走看看