您好我正在写一个解决指定图形问题的小型应用程序。我想使用goraph的maxflow算法(请参阅github.com/gyuho/goraph),但是我将其导入项目时遇到问题。
我做了什么: - 我在我的主目录中创建了一个.go folter并将GOPATH添加到我的.bash_profile中(导出GOPATH = $ HOME / .go)
在我的代码中,我执行以下操作:
package flow
import (
"encoding/json"
"github.com/gyuho/goraph"
"log"
)
//some func definitions...
这是我的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"
调用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
任何人都知道我做错了什么? 谢谢到目前为止
答案 0 :(得分:2)
goraph
project不会仅导入“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
本身。