With Goland in debugging Go-ethereum source encountered some problems, under the guidance of the Great God Goland to fix, in this finishing, hope to help beginners.
When learning Golang, it's no problem to knock the code out of the book, because it's a single file run. But there is a problem with going to run the project, so you need to understand the problem fundamentally.
MinGW
An error occurred while compiling the project:
Compile error so re-download installed MinGW, set path after installation is complete, run
gcc- v
, the ability to print a version indicates that the installation was successful.
Goroot and Gopath
The purpose of the Goroot is to set the Go installation location, and compile the system library from Goroot to find the SDK. If not set, it is obtained from the default location.
The purpose of Gopath is to set the code path, which is required when code is looked up from that path. The code here includes the Project code and the dependency package code that references the external project. GOPATH
can be reset as the project is different.
Gopath must have the following three directories:
- SRC: The directory where the source code is stored, for example,
.go
.h
.c
.
- Pkg: A file generated after compilation, such as
.a
a file, go install
after which a file is generated in that directory .a
.
- Bin: The executable file that was generated after compilation.
Go compiles $GOPATH/src
the required code from the directory.
When a project needs to rely on an external dependency package, go GOPATH
is managed directly. Go allows import
different code base code, for example github.com
, for import
the required code, you can use the command to be removed to the go get
gopath corresponding directory, such as $GOPATH/src/github.com
the next.
So, for go, it's not about whether the code is internal or external, it's all from GOPATH
getting, any import
package path that needs to GOPATH
start. The only difference is that the internally dependent packages are written by the project developers themselves, and the external dependencies are passed go get
down.
Vendor
vendor
The vendor property allows go to compile, first from the project source tree root directory of the directory to find the code (can be understood as a switch GOPATH
), if vendor
there is, then no longer go to Gopath to find.
Therefore, you will copy all the dependencies of the project to the vendor
directory. Use the Package version management tool to handle these things, go official dep
and unofficial glide
etc.