我正在尝试在Go中创建一个简单的计算器。我在设计它时可以先构建一个命令行界面,然后轻松地在GUI界面中进行交换。项目位置为$GOPATH/src/gocalc
(此后所有路径均相对于项目位置)。命令行界面逻辑存储在一个文件中gocalc.go
。计算器逻辑存储在文件calcfns/calcfns.go
和中operations/operations.go
。除了主程序之外,所有文件的软件包名称均与其文件名(无扩展名)相同gocalc.go
。package main
calcfns.go
operations.go
通过进口import "gocalc/operations"
; 通过gocalc.go
进口calcfns.go
import "gocalc/calcfns"
总结一下:
$GOPATH/src/gocalc/
operations.go
package operations
calcfns.go
package calcfns
import "gocalc/operations"
package main
import "gocalc/calcfns"
gocalc.go
calcfns/
operations/
当我尝试go build operations
(从项目目录)时,得到响应:can't load package: package operations: import "operations": cannot find package
当我尝试时go build gocalc/operations
,我得到can't load package: package gocalc/operations: import "gocalc/operations": cannot find package
当我尝试时go build operations/operations.go
,它可以正常编译
当我尝试操作go build calcfns
或时go build gocalc/calcfns
,会收到can't load package...
类似于操作中的消息。但是,当我尝试构建calcfns/calcfns.go
它时,会在import语句上出现问题:import "gocalc/operations": cannot find package
最后,当我go build .
从项目目录尝试时,它与上一段类似,令人窒息:import "gocalc/calcfns": cannot find package
如何go build
以不会失败的方式构造子包和/或导入语句?
慕无忌1623718
相关分类