duanliang1019 2014-05-13 07:16
浏览 509
已采纳

Go语言:找不到导入(github项目)

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条回答 默认 最新

  • dongzhitao4839 2014-05-13 07:32
    关注

    Any example in that goraph project don't import just "github.com/gyuho/goraph".
    They import a specific package within that application:

    For instance:

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器