英文:
how to import local packages?
问题
我的GOPATH和GOROOT
GOPATH="/Users/road/IdeaProjects/MiniJVM"
GOROOT="/usr/local/go"
我的golang项目结构
Myproject
---.idea
---src
   ---cmd
      ---cmd.go
   ---test
      ---test.go
test.go文件,我将使用其他包的导入。我的代码有什么问题?或者导入路径有问题吗?
package main
import (
     "fmt"
     "cmd"
)
func main()  {
     command := &Cmd{}//未解析的类型'Cmd'
}
cmd.go文件
package cmd
import (
	"flag"
	"fmt"
	"os"
)
/*
	jaca [-option] class [args...]
*/
type Cmd struct {
	HelpFlag bool
	VersionFlag bool
	CpOption string
	Class string
	Args []string
}
英文:
My GOPATH and GOROOT
GOPATH="/Users/road/IdeaProjects/MiniJVM"
GOROOT="/usr/local/go"
My golang project structure
Myproject
---.idea
---src
   ---cmd
      ---cmd.go
   ---test
      ---test.go
test.go file, I will use the imports from other packages .What is wrong with my code? Or the import path has some problem?
package main
import (
     "fmt"
     "cmd"
)
func main()  {
     command := &Cmd{}//unresolved type 'Cmd'
}
cmd.go file
package cmd
import (
	"flag"
	"fmt"
	"os"
)
/*
	jaca [-option] class [args...]
*/
type Cmd struct {
	HelpFlag bool
	VersionFlag bool
	CpOption string
	Class string
	Args []string
}
答案1
得分: 1
使用完整路径:
import (
    "github.com/myname/myproject/src/cmd"
)
英文:
Use the full path:
import (
    "github.com/myname/myproject/src/cmd"
)
答案2
得分: 1
你可以将文件夹名称"cmd"更改为其他名称,因为标准库中已经有一个包名为"cmd"的包。
英文:
You may change the folder name "cmd" to other name,because there is already an package "cmd" in the standard library.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论