gpt4 book ai didi

go - 找不到共享库的包

转载 作者:数据小太阳 更新时间:2023-10-29 03:16:05 25 4
gpt4 key购买 nike

我正在尝试在 go-lang 中使用共享库,我正在关注这篇博文:http://blog.ralch.com/tutorial/golang-sharing-libraries/

但是当我点击构建时,我得到了一个错误:

simo@simo:~/gopath$ go build -linkshared -o app effe/prova
src/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/gopath
simo@simo:~/gopath$ echo $GOPATH
/home/simo/gopath
simo@simo:~/gopath$ tree
.
├── pkg
│   └── linux_amd64_dynlink
│   ├── effe
│   │   ├── libmath.a
│   │   └── libmath.shlibname
│   └── libeffe-libmath.so
└── src
└── effe
├── libmath
│   └── libmath.go
└── prova
└── prova.go

7 directories, 5 files
simo@simo:~/gopath$ cat src/effe/libmath/libmath.go
// filename: libmath.go
package libmath

func Sum(x, y int) int {
return x + y
}
simo@simo:~/gopath$ cat src/effe/prova/prova.go
package main

import "libmath"
import "fmt"

func main() {
fmt.Printf("5 op 10 => %d", libmath.Sum(5, 10))
}
simo@simo:~/gopath$ go install -buildmode=shared -linkshared effe/libmath
simo@simo:~/gopath$ go build -linkshared -o app effe/prova
src/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)

我做错了什么?

最佳答案

“libmath”的导入路径是“effe/libmath”。

在尝试更复杂的构建和执行模式之前,请尝试让您的构建在标准构建模式下运行。

关于go - 找不到共享库的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35257574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com