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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀