drecy22400 2012-06-25 05:35 采纳率: 0%
浏览 52
已采纳

为什么“进行构建”找不到软件包?

I installed a test0 package to $gopath\pkg\windows_386\hello\test0.a, but when i build a main package which depends on the test0 package, the compiler says: import "hello/test0": cannot find package.

why this happens?

I have two go file:

$gopath/src/hello.go

package main

import (
    "fmt"
    "hello/test0"
)

func main() {
    fmt.Println(test0.Number)
}

$gopath/src/hello/test0/test0.go

package test0

const (
    Number int = 255
)

At first, i run go install hello/test0, and it generated $gopath\pkg\windows_386\hello\test0.a

then, i delete the directory $gopath/src/hello

finally, i run go build hello.go, and the compiler sayed hello.go:5:2: import "hello/test0": cannot find package

  • 写回答

2条回答 默认 最新

  • doulan1073 2012-06-25 16:09
    关注

    That doesn't seem to be normally possible for the moment : https://code.google.com/p/go/issues/detail?id=2775

    Maybe for Go1.1

    A trick (that I didn't test) by Dave :

    For a package called "hello", the go tool will look for .go sources in $GOPATH/src/hello, and only rebuild if the timestamp of the .a file is before the latest timestamp of the .go files. An easy way to fool it into accepting just the .a file is to drop a dummy .go file in the correct src directory and set its timestamp to before that of the .a file.

    (this is a community answer, using what is said on golang-nuts).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?