英文:
Go language: can't find import (github project)
问题
你好!根据你提供的信息,你在编写一个解决特定图问题的小型Go应用程序。你想要使用goraph的最大流算法(参见github.com/gyuho/goraph),但是在将其导入到你的项目中时遇到了问题。
你已经完成的步骤如下:
- 在你的主目录下创建了一个.go文件夹,并将GOPATH添加到了你的.bash_profile中(export GOPATH=$HOME/.go)。
- 然后你执行了"go get github.com/gyuho/goraph"命令。文件被存储在~/.go/src/github.com/gyuho/goraph中。.go文件夹中还存在一个"bin"文件夹和一个"pkg"文件夹。
在你的代码中,你做了以下操作:
package flow
import (
"encoding/json"
"github.com/gyuho/goraph"
"log"
)
//一些函数定义...
这是我的Makefile:
# Go参数
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOFMT=gofmt -w
# 目录
SRC=src
FLOW_SRC=$(SRC)/flow
ERLANGC_SRC=$(SRC)/erlangc
LOGGING_SRC=$(SRC)/logging
# 名称和文件
MAKING_OS=$(shell go env GOOS)
MAKING_ARCH=$(shell go env GOARCH)
TARGET_NAME=flow
TARGET_DIR=$(shell pwd)/bin
# 交叉编译目标
BIN_DARWIN_AMD64=darwin-amd64
BIN_LINUX_AMD64=linux-amd64
BIN_LINUX_386=linux-386
TARGET_LINUX_AMD64=$(TARGET_DIR)/$(BIN_LINUX_AMD64)/$(TARGET_NAME)
TARGET_LINUX_386=$(TARGET_DIR)/$(BIN_LINUX_386)/$(TARGET_NAME)
TARGET_DARWIN_AMD64=$(TARGET_DIR)/$(BIN_DARWIN_AMD64)/$(TARGET_NAME)
ALL_TARGETS=$(TARGET_LINUX_AMD64) $(TARGET_LINUX_386) $(TARGET_DARWIN_AMD64)
# 规则
all: format tests build-darwin-amd64 build-linux-amd64 build-linux-386
clean: $(ALL_TARGETS)
$(GOCLEAN)
rm -f $^
ci: tests build-linux-amd64
tests:
$(GOTEST) $(FLOW_SRC)/*.go
$(GOTEST) $(ERLANGC_SRC)/*.go
build-darwin-amd64:
mkdir -p $(TARGET_DIR)/$(BIN_DARWIN_AMD64)
cd src && GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(TARGET_DARWIN_AMD64)
build-linux-amd64:
mkdir -p $(TARGET_DIR)/$(BIN_LINUX_AMD64)
cd src && GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(TARGET_LINUX_AMD64)
build-linux-386:
mkdir -p $(TARGET_DIR)/$(BIN_LINUX_386)
cd src && GOARCH=386 GOOS=linux $(GOBUILD) -o $(TARGET_LINUX_386)
format:
$(GOFMT) -d -tabwidth=2 -tabs=false -w -s $(FLOW_SRC)/*.go
$(GOFMT) -d -tabwidth=2 -tabs=false -w -s $(ERLANGC_SRC)/*.go
运行make命令时,你遇到了以下错误:
gofmt -w -d -tabwidth=2 -tabs=false -w -s src/flow/*.go
gofmt -w -d -tabwidth=2 -tabs=false -w -s src/erlangc/*.go
go test src/flow/*.go
# command-line-arguments
src/flow/graph_json.go:5: can't find import: "github.com/gyuho/goraph"
FAIL command-line-arguments [build failed]
make: *** [tests] Error 2
你有没有什么想法,我做错了什么?谢谢!
英文:
Hi I am writing on a small go app solving a specified graph problem. I want to use goraph's maxflow algorithm (see github.com/gyuho/goraph) for this, but I have problems to import it to my project.
What I have done:
-
I created a .go folter in my home directory and added the GOPATH to my .bash_profile (export GOPATH=$HOME/.go)
-
Then I called "go get github.com/gyuho/goraph". The files are stored under ~/.go/src/github.com/gyuho/goraph. In .go also exist a "bin" and a "pkg" folder.
In my code I do the following:
package flow
import (
"encoding/json"
"github.com/gyuho/goraph"
"log"
)
//some func definitions...
This is my Makefile:
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOFMT=gofmt -w
# Directories
SRC=src
FLOW_SRC=$(SRC)/flow
ERLANGC_SRC=$(SRC)/erlangc
LOGGING_SRC=$(SRC)/logging
# Names and files
MAKING_OS=$(shell go env GOOS)
MAKING_ARCH=$(shell go env GOARCH)
TARGET_NAME=flow
TARGET_DIR=$(shell pwd)/bin
# Cross compilation targets
BIN_DARWIN_AMD64=darwin-amd64
BIN_LINUX_AMD64=linux-amd64
BIN_LINUX_386=linux-386
TARGET_LINUX_AMD64=$(TARGET_DIR)/$(BIN_LINUX_AMD64)/$(TARGET_NAME)
TARGET_LINUX_386=$(TARGET_DIR)/$(BIN_LINUX_386)/$(TARGET_NAME)
TARGET_DARWIN_AMD64=$(TARGET_DIR)/$(BIN_DARWIN_AMD64)/$(TARGET_NAME)
ALL_TARGETS=$(TARGET_LINUX_AMD64) $(TARGET_LINUX_386) $(TARGET_DARWIN_AMD64)
# Rules
all: format tests build-darwin-amd64 build-linux-amd64 build-linux-386
clean: $(ALL_TARGETS)
$(GOCLEAN)
rm -f $^
ci: tests build-linux-amd64
tests:
$(GOTEST) $(FLOW_SRC)/*.go
$(GOTEST) $(ERLANGC_SRC)/*.go
build-darwin-amd64:
mkdir -p $(TARGET_DIR)/$(BIN_DARWIN_AMD64)
cd src && GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(TARGET_DARWIN_AMD64)
build-linux-amd64:
mkdir -p $(TARGET_DIR)/$(BIN_LINUX_AMD64)
cd src && GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(TARGET_LINUX_AMD64)
build-linux-386:
mkdir -p $(TARGET_DIR)/$(BIN_LINUX_386)
cd src && GOARCH=386 GOOS=linux $(GOBUILD) -o $(TARGET_LINUX_386)
format:
$(GOFMT) -d -tabwidth=2 -tabs=false -w -s $(FLOW_SRC)/*.go
$(GOFMT) -d -tabwidth=2 -tabs=false -w -s $(ERLANGC_SRC)/*.go
go env:
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bstoecker/.go/"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.2.2/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.2.2/libexec/pkg/tool/darwin_amd64"
TERM="dumb"
CC="clang"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fno-common"
CXX="clang++"
CGO_ENABLED="1"
when calling make I get the following error:
gofmt -w -d -tabwidth=2 -tabs=false -w -s src/flow/*.go
gofmt -w -d -tabwidth=2 -tabs=false -w -s src/erlangc/*.go
go test src/flow/*.go
# command-line-arguments
src/flow/graph_json.go:5: can't find import: "github.com/gyuho/goraph"
FAIL command-line-arguments [build failed]
make: *** [tests] Error 2
anyone an idea what I am doing wrong?
thanks so far
答案1
得分: 2
在goraph
项目中的任何示例中,都不仅仅导入"github.com/gyuho/goraph"这个包。他们导入该应用程序中的特定包:
例如:
import (
"fmt"
"testing"
"github.com/gyuho/goraph/algorithm/bfs"
"github.com/gyuho/goraph/graph/gsd"
// go test -v github.com/gyuho/goraph/example
// go test -v /Users/gyuho/go/src/github.com/gyuho/goraph/example/bfs_test.go
)
看看你能否导入goraph
中的其中一个包,而不是goraph
本身。
英文:
Any example in that goraph
project don't import just "github.com/gyuho/goraph
".
They import a specific package within that application:
For instance:
<!-- language-all: lang-go -->
import (
"fmt"
"testing"
"github.com/gyuho/goraph/algorithm/bfs"
"github.com/gyuho/goraph/graph/gsd"
// go test -v github.com/gyuho/goraph/example
// go test -v /Users/gyuho/go/src/github.com/gyuho/goraph/example/bfs_test.go
)
See if you can import one of those packages within goraph
, instead of goraph
itself.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论