I removed the alias "pri", and it works, thanks! By the way, when go:linkname with runtime, why don't I need to import "runtime" package explicitly?
在 2017年1月20日星期五 UTC+8下午1:34:43,Ian Lance Taylor写道: > > On Wed, Jan 18, 2017 at 6:55 PM, Cholerae Hu <chole...@gmail.com > <javascript:>> wrote: > > I'm trying to play with go:linkname, and I wrote a demo for this. > > > > directory structure: > > > > [test]$ tree > > . > > ├── main.go > > ├── pri > > │ └── a.go > > └── pub > > ├── issue15006.s > > └── b.go > > > > a.go: > > > > package pri > > > > > > import ( > > "fmt" > > ) > > func rua() int64 { > > fmt.Println("rua in pri") > > return 1 > > } > > > > b.go: > > > > package pub > > > > > > import ( > > "unsafe" > > ) > > > > > > var _ = unsafe.Sizeof(0) > > > > > > //go:noescape > > //go:linkname rua test/pri.rua > > func rua() int64 > > > > > > func Rua() int64 { > > return rua() > > } > > > > main.go: > > > > package main > > > > > > import ( > > "test/pub" > > ) > > > > > > func main() { > > println(pub.Rua()) > > } > > > > issue15006.s is a workaround for issue 15006 and it's totally empty. > > > > Than I ran `go run main.go` and got an error: > > > > # command-line-arguments > > test/pub.Rua: test/pri.rua: not defined > > test/pub.Rua: undefined: test/pri.rua > > > > So what's wrong with this demo? > > Nothing in your program imports test/pri. go:linkname only changes > the name used for a symbol. It doesn't cause a package to be > imported. > > Ian > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.