redis - goalng編譯時找不到包
問題描述
windows 7 64位系統,golang 版本1.2go默認安裝在c:GoGOPATH為c:Go_path
測試alphazero/Go-Redis,過程如下文件位置c:go_testre.go,代碼如下:
package mainimport ( 'bufio' 'fmt' 'github.com/alphazero/Go-Redis/redis' 'log' 'os')func main() { spec := redis.DefaultSpec().Db(13) client, e := redis.NewSynchClientWithSpec(spec) if e != nil {log.Println('failed to create the client', e)return } key := 'examples/hello/user.name' value, e := client.Get(key) if e != nil {log.Println('error on Get', e)return } if value == nil {fmt.Printf('nHello, don’t believe we’ve met before!nYour name? ')reader := bufio.NewReader(os.Stdin)user, _ := reader.ReadString(byte(’n’))if len(user) > 1 { user = user[0 : len(user)-1] value = []byte(user) client.Set(key, value)} else { fmt.Printf('vafanculo!n') return} } fmt.Printf('Hey, ciao %s!n', fmt.Sprintf('%s', value))}
c:go_path目錄下有pkg,src,bin,3個目錄首先獲取redis包,執行如下命令
go get github.com/alphazero/Go-Redis/redis
獲取成功,如圖,C:Go_pathpkgwindows_amd64github.comalphazero目錄生成了Go-Redis.acmd進入c:go_test,執行
go run re.go
提示
c:go_test>go run re.gore.go:6:2: cannot find package 'github.com/alphazero/Go-Redis/redis' in any of:C:Gosrcpkggithub.comalphazeroGo-Redisredis (from $GOROOT)C:Go_pathsrcgithub.comalphazeroGo-Redisredis (from $GOPATH)
C:Go_pathsrcgithub.comalphazeroGo-Redis目錄確實有redis.go文件的一直編譯不成功,請問這個是什么情況?
問題解答
回答1:— —!知道了,包含的是目錄而不是文件,所以import的庫應該是
github.com/alphazero/Go-Redis/
但是報這個
C:/Go/bin/go.exe build [C:/go_test]# _/C_/go_test.re.go:6: import C:Go_pathpkgwindows_amd64/github.com/alphazero/Go-Redis.a: object is [windows amd64 go1.1.2 X:none] expected [windows amd64 go1.2 X:none]錯誤: 進程退出代碼 2.
大概是版本限制,我換個redis庫再試試
======================update again=====換了github.com/fzzy/radix/redis庫,用他的測試代碼編譯好了。windows上各種問題...
相關文章:
