无法将函数用作Go中的类型

无法将函数用作Go中的类型,go,Go,我正在尝试从源代码运行以太坊(我想用调试器跟踪执行),但在编译时遇到问题。这就是我得到的错误: [niko@localhost sources]$ go run github.com/ethereum/go-ethereum/cmd/geth/main.go github.com/ethereum/go-ethereum/cmd/geth/config.go github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go github.com/ethe

我正在尝试从源代码运行以太坊(我想用调试器跟踪执行),但在编译时遇到问题。这就是我得到的错误:

[niko@localhost sources]$  go run github.com/ethereum/go-ethereum/cmd/geth/main.go github.com/ethereum/go-ethereum/cmd/geth/config.go github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go github.com/ethereum/go-ethereum/cmd/geth/monitorcmd.go github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go gopkg.in/urfave/cli.v1  --verbosity 5 --ipcdisable --port 40401 --rpc --rpcport 9101 --pprof --datadir=/home/niko/saved-niko-home/myeth/ --networkid=15 console 
# command-line-arguments
github.com/ethereum/go-ethereum/cmd/geth/config.go:42: cannot use dumpConfig (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:43: cannot use initGenesis (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:60: cannot use importChain (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:78: cannot use exportChain (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:95: cannot use removeDB (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/chaincmd.go:108: cannot use dump (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/monitorcmd.go:52: cannot use monitor (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go:50: cannot use importWallet (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go:96: cannot use accountList (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go:107: cannot use accountCreate (type func(*"gopkg.in/urfave/cli.v1".Context) error) as type func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) error in argument to utils.MigrateFlags
github.com/ethereum/go-ethereum/cmd/geth/accountcmd.go:107: too many errors
[niko@localhost sources]$ 
[niko@localhost sources]$ echo $GOPATH
/home/niko/sources/github.com/ethereum/go-ethereum/build/_workspace/:/home/niko/sources/github.com/ethereum/go-ethereum/vendor:/home/niko/go
[niko@localhost sources]$ 
如您所见,它抱怨:

func(*"gopkg.in/urfave/cli.v1".Context)
不同于:

func(*"github.com/ethereum/go-ethereum/vendor/gopkg.in/urfave/cli.v1".Context) 
但是,它是相同的,因为我手动将它复制到/home/niko/go,所有我的
go
包都位于那里:

[niko@localhost sources]$ find /home/niko/go -iname "*cli.v1*"
/home/niko/go/src/gopkg.in/urfave/cli.v1
/home/niko/go/pkg/linux_amd64/gopkg.in/urfave/cli.v1.a
[niko@localhost sources]$ 
它就在我的路上


那么,如何避免这个错误,如何告诉Go这个包是好的呢?

github.com/ethereum/Go ethereum/vendor/gopkg.in/urfave/cli.v1

gopkg.in/urfave/cli.v1

都是不同的导入路径包,无论内容如何,都被认为是不同的

这里的问题是,您的程序不知何故从不同的位置加载了两次,导致出现您提供的错误消息

我不太清楚您使用的
go-run
命令行,我宁愿这样做

go run github.com/ethereum/go-ethereum/cmd/geth/*go --verbosity 5 --ipcdisable --port 40401 --rpc --rpcport 9101 --pprof --datadir=/home/niko/saved-niko-home/myeth/ --networkid=15 console
除非你想入侵以太坊,否则我认为没有理由把它的依赖项复制到你的gopath。 当他们供应商提供其依赖项时(即:他们将其依赖项复制到供应商文件夹中),ref:您真的应该使用这些

关于你的道路

/home/niko/sources/github.com/ethereum/go-ethereum/build/_-workspace/:/home/niko/sources/github.com/ethereum/go-ethereum/vendor:/home/niko/go

我觉得不太好

如果
GOPATH=/home/niko/sources/
,那么

tree $GOPATH -L 1
/home/niko/sources/
├── bin
├── pkg
└── src

3 directories, 0 files
ls-al$GOPATH/src/github.com/ethereum/go-ethereum
应该是正确的


另请参见
go-env

,虽然路径不同,但它并不相同。这使他们different@Flimzy代码所在的路径属于Go的标准位置,可重用包应该位于该位置,即GOPATH目录中,这无关紧要。代码期望它被出售。因此,如果它不在供应商目录中,则是错误的。@Flimzy我如何指定文件的确切位置?因为我已将它们从一个地方复制到另一个地方几个小时了,但它不起作用。你根本不应该复制/移动它们。供应商提供的文件通常应随源程序包一起提供。是的,您完全正确,函数定义了两次,因为我在命令行中手动提供源文件。但是,如果我省略它们,我会遇到另一个问题,发布在这里:在src、pkg目录中列出源代码之后,它就工作了。谢谢