找不到共享库的包。

huangapple go评论79阅读模式
英文:

Cannot find package for shared library

问题

我正在尝试在Go语言中使用一个共享库,我正在按照这篇博文进行操作: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: 找不到包"libmath",在以下任何位置都找不到:
/usr/local/go/src/libmath (来自$GOROOT)
/home/simo/gopath/src/libmath (来自$GOPATH)

我对Go语言还不太熟悉,所以我也会展示我的环境信息...

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: 找不到包"libmath",在以下任何位置都找不到:
/usr/local/go/src/libmath (来自$GOROOT)
/home/simo/gopath/src/libmath (来自$GOPATH)

我做错了什么?

英文:

I am trying to use a shared library in go-lang, I am following this blog post: http://blog.ralch.com/tutorial/golang-sharing-libraries/

But when I hit build I get back an error:

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)

I am pretty new to go, so I will show also my environment...

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)

What am I doing wrong ?

答案1

得分: 1

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

在尝试更复杂的构建和执行模式之前,先尝试在标准构建模式下使您的构建工作正常。

英文:

The import path for "libmath" is "effe/libmath".

Try to get your build working in the standard build mode before experimenting with more complicated build and execution modes.

huangapple
  • 本文由 发表于 2016年2月8日 02:47:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/35257574.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定