douyuefei3546 2016-07-19 10:41
浏览 31

“运行”,但是注意到我缺少.a文件(我已经运行“运行”)

I want to run a go file, main package imported a local package which imported a github package. and get an error (missing .a file)

ENV: $GOROOT=/usr/local/go $GOPATH=/gopath

go version 1.6.3 (same problem in 1.6.2)

I tried to run a go file like this:

/gopath/src/myproj/main/app.go

package main

import (
  "../http/server"
)

func main() {
  server.Run()
}

/gopath/src/myproj/http/server/route.go

package server

import (
    "github.com/gorilla/mux"
    "net/http"
)

func Run(){
    router := mux.NewRouter()
    router.HandleFunc("/", handler)
    http.Handle("/", router)
    http.ListenAndServe("9090", nil)
}

func handler(res http.ResponseWriter, req *http.Request) {
    res.Write([]byte("Hello"))
}

then,I run go get github.com/gorilla/mux and I can see there are files

/gopath/pkg/linux_amd64/github.com/gorilla/mux (there are context.a and mux.a)
/gopath/src/github.com/gorilla/mux
/gopath/src/github.com/gorilla/context

Yes, src file and pkg file(.a) has downloaded form github,

BUT , I run "go run main/app.go" , get

# command-line-arguments
/usr/local/go/pkg/tool/linux_amd64/link: cannot open file /usr/local/go/pkg/linux_amd64/github.com/gorilla/mux.a: open /usr/local/go/pkg/linux_amd64/github.com/gorilla/mux.a: no such file or directory

compiler does not find file in GOPATH, but GOROOT if I copy $GOPATH/pkg files to $GOROOT/pkg was good.

And, if I import github.com/gorilla/mux in main package directly was fine too.

  • 写回答

1条回答 默认 最新

  • dqw7121 2018-04-21 21:28
    关注

    As JimB said don't use relative paths for imports

    if you change "../http/server" to myproj/http/server it shouldn't have the linking problems anymore

    评论

报告相同问题?

悬赏问题

  • ¥15 processing提取音乐节奏
  • ¥15 python进程启动打包问题
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条