[Learning Notes] Goland Project compiling and debugging

Source: Internet
Author: User

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. GOPATHcan 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

vendorThe 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.