Go compilation issues

Source: Internet
Author: User

Golang is compiled using the command go build, go install, or the directory structure is ready unless you write only a main function,
gopath= the project root directory, under which the Src,pkg,bin directory should be created, which is used to build the executable file in the bin directory , the PKG directory is used to generate. A files,
Golang in the import name, is actually to Gopath to find Name.a, when used is the name.a of the source of life of the package name; This has been described in the previous.

Note:
1. When the system compiles go install Abc_name, the system will go to Gopath's src directory to find the Abc_name directory, and then compile the go file under it;
2. The package declaration must be the same for all go files in the same directory, so the main method is to put a separate file, otherwise it will be an error in Eclipse and liteide;
    The compilation error is as follows: (suppose there is a main.go and mymath.go in the test directory, where Main.go declares that the package is Main,mymath.go declaration packag is test);
    $ Go install test
    can ' t load package:package test:found Packages main (MAIN.GO) and test (mymath.go) in/home/wanjm/go/src/test
    error saying the package could not be loaded Test (This is the command-line parameter) because two package was found, respectively Main.go and mymath.go;
3. For the main method, you can only run go build path_tomain.go in the bin directory; the output file name is indicated by the-o parameter;
4. You can add the parameter go build-gcflags "-n-l"   * * *, can be more good for gdb; see Http://golang.org/doc/gdb
5. GDB global variable Master point. If there is a global variable A; it should be written as P ' main.a '; note but the quotation marks are not small;

Go compilation issues

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.