dongye4192 2019-09-11 17:26
浏览 82
已采纳

Go库:找不到提供包lib的模块

I am creating 3 separate go projects: ace, aces-client and a library shared by both projects aceslib. I am having trouble including the shared library according to the go-documentation (https://golang.org/doc/code.html#Library)

all go files in aceslib share the package-name aceslib. I am including the library in ace and aces-client with import lib "aceslib". I can build the library with go build and it gets installed with go install, in the directory listing one can see that the file go/pkg/windows_amd64/aceslib.a gets created.

But when I try to build ace or ace-client go complains:

$ go build 
build ace: cannot load aceslib: cannot find module providing package aceslib

My go setup:

$ go version
go version go1.12.9 windows/amd64
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Yulivee\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\Yulivee\go
set GOPROXY=
set GORACE=
set GOROOT=c:\go
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\Users\Yulivee\go\src\ace\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Yulivee\AppData\Local\Temp\go-build024649150=/tmp/go-build -gno-record-gcc-switches

Directory Structure:

.
├── bin
│   ├── ace-client.exe
│   └── ace.exe
├── pkg
│   ├── mod
│   │   ├── cache
│   │   └── golang.org
│   └── windows_amd64
│       ├── ace
│       ├── aceslib.a
│       └── golang.org
└── src
    ├── ace
    │   ├── README.md
    │   ├── go.mod
    │   ├── go.sum
    │   └── main.go
    ├── ace-client
    │   └── main.go
    ├── aceslib
    │   ├── README.md
    │   ├── crypto.go
    │   ├── go.mod
    │   └── utils.go

What am I missing?


Things I have tried, that did not help and lead to the same error:

$ go clean -i -x -cache -modcache
$ chmod 755 go/pkg/windows_amd64/aceslib.a
$ go get
build ace: cannot load aceslib: cannot find module providing package aceslib
$ rm -rf go/pkg/*
  • 写回答

2条回答 默认 最新

  • douhuangjian9627 2019-09-11 17:52
    关注

    The directory structure and package names are a bit off - it should be a URL to your project's repo, like every other import that isn't from the stdlib. If you have no repo and want to use local references you'll need to add a replace directive to ace/go.mod like so:

    replace aceslib => ../aceslib
    

    As documented in the Modules docs.

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

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效