AlekSi/cgo-by-example

cannot find package "github.com/AlekSi/cgo-by-example/wrapper"

Closed this issue · 5 comments

I just downloaded the Git source and ran make:

gofmt -e -s -w .
go vet .
cc -g -fPIC -c -o lib/lib.o lib/lib.c
cc -g -fPIC -shared -o liblib.so lib/lib.o
LD_LIBRARY_PATH=. go run main.go
f0()
f1(5)
f1(8)
f2(Go string)
fmt: return f2(Go string)
f31: s1={5}, s1Ret={10}
f32: s1={10}, s1Ret={10}
s2={0xc82000a460}, _s2.p=8, i=8
f4: s2={0xc82000a460}, *s2.p=16, i=8
f1(0)
f1(1)
f1(2)
cp liblib.so wrapper/
LD_LIBRARY_PATH=. go run main2.go
main2.go:7:2: cannot find package "github.com/AlekSi/cgo-by-example/wrapper" in any of:
 /usr/lib/golang/src/github.com/AlekSi/cgo-by-example/wrapper (from $GOROOT)
 ($GOPATH not set)
Makefile:2: recipe for target 'all' failed
make: *_\* [all] Error 1

$GOPATH not set

You must set GOPATH: https://golang.org/doc/code.html

Thanks, I set it and got another error:

(virtualenv)[][14:50:39][/tmp/cgo-by-example]$ make
gofmt -e -s -w .
go vet .
cc -g -fPIC -c -o lib/lib.o lib/lib.c
cc -g -fPIC -shared -o liblib.so lib/lib.o
LD_LIBRARY_PATH=. go run main.go
f0()
f1(5)
f1(8)
f2(Go string)
fmt: return f2(Go string)
f31: s1={5}, s1Ret={10}
f32: s1={10}, s1Ret={10}
s2={0xc82000a460}, *s2.p=8, i=8
f4: s2={0xc82000a460}, *s2.p=16, i=8
f1(0)
f1(1)
f1(2)
cp liblib.so wrapper/
LD_LIBRARY_PATH=. go run main2.go
main2.go:7:2: cannot find package "github.com/AlekSi/cgo-by-example/wrapper" in any of:
        /usr/lib/golang/src/github.com/AlekSi/cgo-by-example/wrapper (from $GOROOT)
        /tmp/cgo-by-example/src/github.com/AlekSi/cgo-by-example/wrapper (from $GOPATH)
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
(virtualenv)[][14:50:54][/tmp/cgo-by-example][2] $ echo $GOPATH 
/tmp/cgo-by-example

It's still a problem with GOPATH. You should place sources to $GOPATH/src/github.com/AlekSi/cgo-by-example, not just to $GOPATH.

Okay, I confirm that it works then. Thanks!

Keep in mind that this repository is probably outdated. For example, it doesn't cover pure Go dynamic-link library.