Siscia
Siscia

Reputation: 1481

Cannot find package for shared library

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 ?

Upvotes: 0

Views: 551

Answers (1)

Mr_Pink
Mr_Pink

Reputation: 109337

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.

Upvotes: 1

Related Questions