Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top