我正在尝试在 go-lang 中使用共享库,我正在关注这篇博文:http : //blog.ralch.com/tutorial/golang-sharing-libraries/但是当我点击构建时,我得到一个错误:simo@simo:~/gopath$ go build -linkshared -o app effe/provasrc/effe/prova/prova.go:3:8: cannot find package "libmath" in any of:/usr/local/go/src/libmath (from $GOROOT)/home/simo/gopath/src/libmath (from $GOPATH)我是新手,所以我也会展示我的环境......simo@simo:~/gopath$ pwd/home/simo/gopathsimo@simo:~/gopath$ echo $GOPATH/home/simo/gopathsimo@simo:~/gopath$ tree.├── pkg│ └── linux_amd64_dynlink│ ├── effe│ │ ├── libmath.a│ │ └── libmath.shlibname│ └── libeffe-libmath.so└── src └── effe ├── libmath │ └── libmath.go └── prova └── prova.go7 directories, 5 filessimo@simo:~/gopath$ cat src/effe/libmath/libmath.go // filename: libmath.gopackage libmathfunc Sum(x, y int) int { return x + y}simo@simo:~/gopath$ cat src/effe/prova/prova.go package mainimport "libmath"import "fmt"func main() { fmt.Printf("5 op 10 => %d", libmath.Sum(5, 10))}simo@simo:~/gopath$ go install -buildmode=shared -linkshared effe/libmathsimo@simo:~/gopath$ go build -linkshared -o app effe/provasrc/effe/prova/prova.go:3:8: cannot find package "libmath" in any of: /usr/local/go/src/libmath (from $GOROOT) /home/simo/gopath/src/libmath (from $GOPATH)我究竟做错了什么 ?
1 回答
ITMISS
TA贡献1871条经验 获得超8个赞
好的,两件事:
你没有“继承”
io.Writer
(你只是说你的结构包含一个作家)。在 go 中,接口是隐式的。如果您的结构实现了Write(p []byte) (n int, err, error)
,则它是一个io.Writer
并且可以与任何接受它的函数一起使用。时期。不需要申报任何东西。至于你的问题:
fmt.Printf("%s\n", string(p))
- 1 回答
- 0 关注
- 341 浏览
添加回答
举报
0/150
提交
取消